how do i deserialize json file like this:
{
"misterislukelis": {
"id": 44816005,
"name": "MisterisLukelis",
"profileIconId": 1391,
"summonerLevel": 30,
"revisionDate": 1479601967000
}
}
from whati gathered this is json "dictionary" but i dont know do i read it same as normal json file
ex. of normal json:
[ {
"application_id":"1",
"application_package":"abc"
},
{
"application_id":"2",
"application_package":"xyz"
} ]
i don't know it they behave diferently, becouse as much as i looked in it, every one just does same thing, but for me it doesnt really work
my class:
Class summoner 'class opening
Public Property id As Integer 'summoner's id
Public Property name As String 'summoner's name
Public Property profileIconId As Integer 'profile icon id
Public Property summonerLevel As Integer 'summoner's level
End Class 'end of a class
and then this should deserialize the json:
Dim ser As JavaScriptSerializer = New JavaScriptSerializer()
Dim jsonData As String = readData(URLadress) 'get json file in to txt(i have function fo it, it works i triple checked)
Dim summonerInfo As summoner = ser.Deserialize(Of summoner)(jsonData) 'deserialize json
TextBox1.Text = summonerInfo.summonerLevel 'print out summoner level
as i looked this should work fine but all i get where integer should be i get 0, where string i get " ", i really dont know where the problem is
the second example is a json Array and works fine with Deserialize json.
Dim webtest As String = "[ {
""application_id"":""1"",
""application_package"":""abc""
},
{
""application_id"":""2"",
""application_package"":""xyz""
} ]"
Dim serializer As New JavaScriptSerializer()
Dim webtestdeserialized As New List(Of cSummoner)
webtestdeserialized = serializer.Deserialize(Of List(Of cSummoner))(webtest) '(serializedResult)
I have with JSON Object a proble, too. The JSON Object i get it in a Object, but not in a list of cSummoner.
Dim webtest As String = "{
""id"": 44816005,
""name"": ""MisterisLukelis"",
""profileIconId"": 1391,
""summonerLevel"": 30,
""revisionDate"": 1479601967000
}"
Dim serializer As New JavaScriptSerializer()
Dim webtestdeserialized As Object
webtestdeserialized = serializer.DeserializeObject(webtest)
I hope i can help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.