@styx作品上面的答案,但我已經改變我的代碼。這個答案僅供參考。
我創建了一個名爲PerInfo
public class PerInfo
public firstname
public lastname
end class
要序列化,我寫這個類;
dim x as new PerInfo
x.firstname = textbox1.text
x.address = textbox2.text
dim res as string = JsonConvert.SerializeObject(x)
' the above code produces my desired result which is
' {"firstname":"jeo","address":"GSC"}
要反序列化,我做了這個;
Dim t As PerInfo = JsonConvert.DeserializeObject(Of PerInfo)(x)
'I can now access the `firstname` and `address` via
' t.firstname and t.address
MsgBox(t.firstname & "===" & t.address)
希望這有助於...
PS:我通過添加引用手動添加的Newtonsoft.Json.dll
版本Net 2.0
爲使用.net 2.0
框架,如果我是對PC的向後兼容性。隨意糾正我這一點。
我在閱讀您的答案之前更改了我的代碼。根據我的問題,你的代碼工作,併產生我想要的確切結果,很酷。但是由於我的引用中沒有system.web.script.serialization,所以我很難對這個對象進行反序列化(「因爲我是VB.net上的新手」),我不知道爲什麼我可以'在我的參考資料上找到它,我只有system.web.services。謝謝你,先生。我很感激。 –