vb.net json.net反序列化长json [英] vb.net json.net deserializing long json
问题描述
目前在vb.net中使用JSON.Net读取命运JSON文件的程序。
这是JSON文件。
Currently working on a program in vb.net that uses JSON.Net to read the destiny JSON files.
This is the JSON file.
{
"Response" : {
"data" : {
"membershipId" : "4611686018444289561",
"membershipType" : 2,
"characters" : [{
"characterBase" : {
"membershipId" : "4611686018444289561",
"membershipType" : 2,
"characterId" : "2305843009266226944",
"dateLastPlayed" : "2015-06-22T21:43:06Z",
"minutesPlayedThisSession" : "0",
"minutesPlayedTotal" : "17109",
"powerLevel" : 34,
"raceHash" : 2803282938,
"genderHash" : 2204441813,
"classHash" : 671679327,
"currentActivityHash" : 0,
"lastCompletedStoryHash" : 0,
"stats" : {
"STAT_DEFENSE" : {
"statHash" : 3897883278,
"value" : 1786,
"maximumValue" : 0
},
"STAT_INTELLECT" : {
"statHash" : 144602215,
"value" : 147,
"maximumValue" : 0
},
"STAT_DISCIPLINE" : {
"statHash" : 1735777505,
"value" : 266,
"maximumValue" : 0
},
"STAT_STRENGTH" : {
"statHash" : 4244567218,
"value" : 144,
"maximumValue" : 0
},
"STAT_LIGHT" : {
"statHash" : 2391494160,
"value" : 168,
"maximumValue" : 0
},
"STAT_ARMOR" : {
"statHash" : 392767087,
"value" : 8,
"maximumValue" : 0
},
"STAT_AGILITY" : {
"statHash" : 2996146975,
"value" : 5,
"maximumValue" : 0
},
"STAT_RECOVERY" : {
"statHash" : 1943323491,
"value" : 4,
"maximumValue" : 0
},
"STAT_OPTICS" : {
"statHash" : 3555269338,
"value" : 55,
"maximumValue" : 0
}
},
"customization" : {
"personality" : 2166136261,
"face" : 2695914755,
"skinColor" : 1815484265,
"lipColor" : 2844894632,
"eyeColor" : 1511637744,
"hairColor" : 1222512333,
"featureColor" : 2166136261,
"decalColor" : 2133206350,
"wearHelmet" : false,
"hairIndex" : 1,
"featureIndex" : 0,
"decalIndex" : 7
},
"grimoireScore" : 2680,
"peerView" : {
"equipment" : [{
"itemHash" : 1716862031,
"dyes" : []
}, {
"itemHash" : 144553854,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 3354041935
}, {
"channelHash" : 1367384683,
"dyeHash" : 3419191362
}, {
"channelHash" : 218592586,
"dyeHash" : 3389671913
}
]
}, {
"itemHash" : 3387472392,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 3354041935
}, {
"channelHash" : 1367384683,
"dyeHash" : 3419191362
}, {
"channelHash" : 218592586,
"dyeHash" : 3389671913
}
]
}, {
"itemHash" : 1496660238,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 3354041935
}, {
"channelHash" : 1367384683,
"dyeHash" : 3419191362
}, {
"channelHash" : 218592586,
"dyeHash" : 3389671913
}
]
}, {
"itemHash" : 3637940699,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 3354041935
}, {
"channelHash" : 1367384683,
"dyeHash" : 3419191362
}, {
"channelHash" : 218592586,
"dyeHash" : 3389671913
}
]
}, {
"itemHash" : 2282906673,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 1096181162
}, {
"channelHash" : 1367384683,
"dyeHash" : 1652075411
}, {
"channelHash" : 218592586,
"dyeHash" : 2703491298
}
]
}, {
"itemHash" : 3164616405,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 3925656441
}, {
"channelHash" : 1667433278,
"dyeHash" : 3223521410
}
]
}, {
"itemHash" : 3327140886,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 421485277
}, {
"channelHash" : 1667433278,
"dyeHash" : 2764135478
}
]
}, {
"itemHash" : 3153232297,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 3805233741
}, {
"channelHash" : 1667433278,
"dyeHash" : 2741135462
}
]
}, {
"itemHash" : 1388583990,
"dyes" : [{
"channelHash" : 284967655,
"dyeHash" : 2328943074
}, {
"channelHash" : 840921382,
"dyeHash" : 162237873
}
]
}, {
"itemHash" : 3703598457,
"dyes" : [{
"channelHash" : 2025709351,
"dyeHash" : 794303093
}
]
}, {
"itemHash" : 2751204699,
"dyes" : [{
"channelHash" : 4023194814,
"dyeHash" : 1177926279
}
]
}, {
"itemHash" : 1825970520,
"dyes" : []
}, {
"itemHash" : 1947545036,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 3354041935
}, {
"channelHash" : 1367384683,
"dyeHash" : 3419191362
}, {
"channelHash" : 218592586,
"dyeHash" : 3389671913
}
]
}
]
},
"genderType" : 1,
"classType" : 1,
"buildStatGroupHash" : 633635316
},
"levelProgression" : {
"dailyProgress" : 0,
"weeklyProgress" : 10925,
"currentProgress" : 3769138,
"level" : 47,
"step" : 0,
"progressToNextLevel" : 9138,
"nextLevelAt" : 80000,
"progressionHash" : 2030054750
},
"emblemPath" : "/common/destiny_content/icons/71891e9447353b5adf45a55e1d5e0fee.jpg",
"backgroundPath" : "/common/destiny_content/icons/d482a38c8062563aa3bc641856b85161.jpg",
"emblemHash" : 1825970520,
"characterLevel" : 34,
"baseCharacterLevel" : 20,
"isPrestigeLevel" : true,
"percentToNextLevel" : 0.0
}, {
"characterBase" : {
"membershipId" : "4611686018444289561",
"membershipType" : 2,
"characterId" : "2305843009270904041",
"dateLastPlayed" : "2015-06-12T04:41:28Z",
"minutesPlayedThisSession" : "0",
"minutesPlayedTotal" : "1998",
"powerLevel" : 30,
"raceHash" : 3887404748,
"genderHash" : 2204441813,
"classHash" : 2271682572,
"currentActivityHash" : 0,
"lastCompletedStoryHash" : 0,
"stats" : {
"STAT_DEFENSE" : {
"statHash" : 3897883278,
"value" : 1509,
"maximumValue" : 0
},
"STAT_INTELLECT" : {
"statHash" : 144602215,
"value" : 130,
"maximumValue" : 0
},
"STAT_DISCIPLINE" : {
"statHash" : 1735777505,
"value" : 182,
"maximumValue" : 0
},
"STAT_STRENGTH" : {
"statHash" : 4244567218,
"value" : 177,
"maximumValue" : 0
},
"STAT_LIGHT" : {
"statHash" : 2391494160,
"value" : 126,
"maximumValue" : 0
},
"STAT_ARMOR" : {
"statHash" : 392767087,
"value" : 9,
"maximumValue" : 0
},
"STAT_AGILITY" : {
"statHash" : 2996146975,
"value" : 5,
"maximumValue" : 0
},
"STAT_RECOVERY" : {
"statHash" : 1943323491,
"value" : 7,
"maximumValue" : 0
},
"STAT_OPTICS" : {
"statHash" : 3555269338,
"value" : 49,
"maximumValue" : 0
}
},
"customization" : {
"personality" : 2166136261,
"face" : 2132087823,
"skinColor" : 3045033367,
"lipColor" : 404671481,
"eyeColor" : 1194006502,
"hairColor" : 2739213077,
"featureColor" : 2166136261,
"decalColor" : 2714701677,
"wearHelmet" : false,
"hairIndex" : 11,
"featureIndex" : 0,
"decalIndex" : 6
},
"grimoireScore" : 2680,
"peerView" : {
"equipment" : [{
"itemHash" : 3828867689,
"dyes" : []
}, {
"itemHash" : 813361818,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 2431473053
}, {
"channelHash" : 1367384683,
"dyeHash" : 2332768436
}, {
"channelHash" : 218592586,
"dyeHash" : 1281112403
}
]
}, {
"itemHash" : 1050422086,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 2775740718
}, {
"channelHash" : 1367384683,
"dyeHash" : 3142008767
}, {
"channelHash" : 218592586,
"dyeHash" : 291630158
}
]
}, {
"itemHash" : 3411635687,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 2775740718
}, {
"channelHash" : 1367384683,
"dyeHash" : 3142008767
}, {
"channelHash" : 218592586,
"dyeHash" : 291630158
}
]
}, {
"itemHash" : 2797907388,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 2775740718
}, {
"channelHash" : 1367384683,
"dyeHash" : 3142008767
}, {
"channelHash" : 218592586,
"dyeHash" : 291630158
}
]
}, {
"itemHash" : 2675543791,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 1537857451
}, {
"channelHash" : 1367384683,
"dyeHash" : 1501873614
}, {
"channelHash" : 218592586,
"dyeHash" : 504218347
}
]
}, {
"itemHash" : 3667595457,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 401101184
}, {
"channelHash" : 1667433278,
"dyeHash" : 3599482519
}
]
}, {
"itemHash" : 1325979471,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 716482169
}, {
"channelHash" : 1667433278,
"dyeHash" : 14347138
}
]
}, {
"itemHash" : 1274330686,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 2289053638
}, {
"channelHash" : 1667433278,
"dyeHash" : 567827245
}
]
}, {
"itemHash" : 671526061,
"dyes" : [{
"channelHash" : 284967655,
"dyeHash" : 1437417001
}, {
"channelHash" : 840921382,
"dyeHash" : 2751843408
}
]
}, {
"itemHash" : 3703598457,
"dyes" : [{
"channelHash" : 2025709351,
"dyeHash" : 794303093
}
]
}, {
"itemHash" : 2751204699,
"dyes" : [{
"channelHash" : 4023194814,
"dyeHash" : 1177926279
}
]
}, {
"itemHash" : 1825970523,
"dyes" : []
}, {
"itemHash" : 1947545037,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 2775740718
}, {
"channelHash" : 1367384683,
"dyeHash" : 3142008767
}, {
"channelHash" : 218592586,
"dyeHash" : 291630158
}
]
}
]
},
"genderType" : 1,
"classType" : 2,
"buildStatGroupHash" : 2172613790
},
"levelProgression" : {
"dailyProgress" : 0,
"weeklyProgress" : 0,
"currentProgress" : 315183,
"level" : 3,
"step" : 0,
"progressToNextLevel" : 75183,
"nextLevelAt" : 80000,
"progressionHash" : 2030054750
},
"emblemPath" : "/common/destiny_content/icons/d6e630844fce9b8f875b9945a9d3ca5b.jpg",
"backgroundPath" : "/common/destiny_content/icons/6c4a10751aef0067be54dc2461711ea4.jpg",
"emblemHash" : 1825970523,
"characterLevel" : 30,
"baseCharacterLevel" : 20,
"isPrestigeLevel" : true,
"percentToNextLevel" : 50.0
}, {
"characterBase" : {
"membershipId" : "4611686018444289561",
"membershipType" : 2,
"characterId" : "2305843009306714231",
"dateLastPlayed" : "2015-06-12T04:40:44Z",
"minutesPlayedThisSession" : "31",
"minutesPlayedTotal" : "369",
"powerLevel" : 1,
"raceHash" : 898834093,
"genderHash" : 2204441813,
"classHash" : 3655393761,
"currentActivityHash" : 0,
"lastCompletedStoryHash" : 0,
"stats" : {
"STAT_DEFENSE" : {
"statHash" : 3897883278,
"value" : 214,
"maximumValue" : 0
},
"STAT_INTELLECT" : {
"statHash" : 144602215,
"value" : 0,
"maximumValue" : 0
},
"STAT_DISCIPLINE" : {
"statHash" : 1735777505,
"value" : 0,
"maximumValue" : 0
},
"STAT_STRENGTH" : {
"statHash" : 4244567218,
"value" : 78,
"maximumValue" : 0
},
"STAT_ARMOR" : {
"statHash" : 392767087,
"value" : 5,
"maximumValue" : 0
},
"STAT_AGILITY" : {
"statHash" : 2996146975,
"value" : 1,
"maximumValue" : 0
},
"STAT_RECOVERY" : {
"statHash" : 1943323491,
"value" : 1,
"maximumValue" : 0
},
"STAT_OPTICS" : {
"statHash" : 3555269338,
"value" : 49,
"maximumValue" : 0
}
},
"customization" : {
"personality" : 2166136261,
"face" : 2552882596,
"skinColor" : 4232663426,
"lipColor" : 1955118883,
"eyeColor" : 4187018147,
"hairColor" : 2324992807,
"featureColor" : 2166136261,
"decalColor" : 424152543,
"wearHelmet" : false,
"hairIndex" : 10,
"featureIndex" : 0,
"decalIndex" : 3
},
"grimoireScore" : 2680,
"peerView" : {
"equipment" : [{
"itemHash" : 2007186000,
"dyes" : []
}, {
"itemHash" : 706892687,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 747964525
}, {
"channelHash" : 1367384683,
"dyeHash" : 3147373164
}, {
"channelHash" : 218592586,
"dyeHash" : 1346091505
}
]
}, {
"itemHash" : 4042984494,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 215207960
}, {
"channelHash" : 1367384683,
"dyeHash" : 2280395877
}, {
"channelHash" : 218592586,
"dyeHash" : 768586838
}
]
}, {
"itemHash" : 1742813176,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 1250341018
}, {
"channelHash" : 1367384683,
"dyeHash" : 3468588859
}, {
"channelHash" : 218592586,
"dyeHash" : 4089917164
}
]
}, {
"itemHash" : 924874407,
"dyes" : [{
"channelHash" : 662199250,
"dyeHash" : 1431052853
}, {
"channelHash" : 1367384683,
"dyeHash" : 205143812
}, {
"channelHash" : 218592586,
"dyeHash" : 1119419865
}
]
}, {
"itemHash" : 1599594923,
"dyes" : []
}, {
"itemHash" : 1284289562,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 129049218
}, {
"channelHash" : 1667433278,
"dyeHash" : 831184249
}
]
}, {
"itemHash" : 811663330,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 2346743114
}, {
"channelHash" : 1667433278,
"dyeHash" : 4028939073
}
]
}, {
"itemHash" : 3167958228,
"dyes" : [{
"channelHash" : 1667433279,
"dyeHash" : 3449915848
}, {
"channelHash" : 1667433278,
"dyeHash" : 3907340927
}
]
}, {
"itemHash" : 1388583991,
"dyes" : [{
"channelHash" : 284967655,
"dyeHash" : 1571237171
}, {
"channelHash" : 840921382,
"dyeHash" : 4188234966
}
]
}, {
"itemHash" : 3703598457,
"dyes" : [{
"channelHash" : 2025709351,
"dyeHash" : 794303093
}
]
}, {
"itemHash" : 2751204699,
"dyes" : [{
"channelHash" : 4023194814,
"dyeHash" : 1177926279
}
]
}, {
"itemHash" : 1443409303,
"dyes" : []
}, {
"itemHash" : 4248210736,
"dyes" : []
}
]
},
"genderType" : 1,
"classType" : 0,
"buildStatGroupHash" : 3801959103
},
"levelProgression" : {
"dailyProgress" : 8395,
"weeklyProgress" : 8395,
"currentProgress" : 69375,
"level" : 10,
"step" : 0,
"progressToNextLevel" : 6875,
"nextLevelAt" : 13000,
"progressionHash" : 1716568313
},
"emblemPath" : "/common/destiny_content/icons/ee9d2fe8b039751ad3d9e48c7f476dc2.jpg",
"backgroundPath" : "/common/destiny_content/icons/e99ee1ccf976e482c274a2782283cd7d.jpg",
"emblemHash" : 1443409303,
"characterLevel" : 10,
"baseCharacterLevel" : 10,
"isPrestigeLevel" : false,
"percentToNextLevel" : 52.8846169
}
],
"inventory" : {
"buckets" : {
"Invisible" : [],
"Item" : [],
"Currency" : []
},
"currencies" : [{
"itemHash" : 3159615086,
"value" : 7022
}
]
},
"grimoireScore" : 2680,
"versions" : 7
}
},
"ErrorCode" : 1,
"ThrottleSeconds" : 0,
"ErrorStatus" : "Success",
"Message" : "Ok",
"MessageData" : {}
}
我试图拉出每个角色的所有数据,并以不同的方式在表格上显示,但现在我很乐意在消息框中显示信息,以确保它正常工作。
这是我当前的代码,有一个建议为json创建类,这就是我到目前为止所做的,但我仍然不确定如何提取我需要的信息,我不确定我应该把列表放在哪个方面,正如你从我的代码中看到的那样,我有两种不同的方式来测试每种方式,看看哪些方法有效,但是我可以接受建议,因为我自己也没有得到任何建议。
Im trying to pull all the data for each character and display it on the form in different ways but for now i would be happy to show the information in a message box just to make sure it is working.
This is my current code, there was a suggestion to create classes for the json and thats what i have done so far, but im still unsure of how to pull the information i need, and im not sure which way i should put lists, as you can see from my code, i have them in 2 different ways to test each way and see what works but im open to suggestions as im not getting anywhere by myself.
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Net
Imports System.IO
'BungieNetPlatform
Imports BungieNetPlatform
Imports Extensions
Imports System.Text
Public Class STATDEFENSE
Public Property statHash As Object
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATINTELLECT
Public Property statHash As Integer
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATDISCIPLINE
Public Property statHash As Integer
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATSTRENGTH
Public Property statHash As Object
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATLIGHT
Public Property statHash As Object
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATARMOR
Public Property statHash As Integer
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATAGILITY
Public Property statHash As Object
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATRECOVERY
Public Property statHash As Integer
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class STATOPTICS
Public Property statHash As Object
Public Property value As Integer
Public Property maximumValue As Integer
End Class
Public Class Stats
Public Property STAT_DEFENSE As List(Of STATDEFENSE)
Public Property STAT_INTELLECT As List(Of STATINTELLECT)
Public Property STAT_DISCIPLINE As STATDISCIPLINE
Public Property STAT_STRENGTH As STATSTRENGTH
Public Property STAT_LIGHT As STATLIGHT
Public Property STAT_ARMOR As STATARMOR
Public Property STAT_AGILITY As STATAGILITY
Public Property STAT_RECOVERY As STATRECOVERY
Public Property STAT_OPTICS As STATOPTICS
End Class
Public Class Customization
Public Property personality As Object
Public Property face As Object
Public Property skinColor As Object
Public Property lipColor As Long
Public Property eyeColor As Long
Public Property hairColor As Object
Public Property featureColor As Object
Public Property decalColor As Long
Public Property wearHelmet As Boolean
Public Property hairIndex As Integer
Public Property featureIndex As Integer
Public Property decalIndex As Integer
End Class
Public Class Dye
Public Property channelHash As Object
Public Property dyeHash As Object
End Class
Public Class Equipment
Public Property itemHash As Object
Public Property dyes As Dye()
End Class
Public Class PeerView
Public Property equipment As Equipment()
End Class
Public Class CharacterBase
Public Property membershipId As String
Public Property membershipType As Integer
Public Property characterId As String
Public Property dateLastPlayed As DateTime
Public Property minutesPlayedThisSession As String
Public Property minutesPlayedTotal As String
Public Property powerLevel As Integer
Public Property raceHash As Object
Public Property genderHash As Object
Public Property classHash As Object
Public Property currentActivityHash As Integer
Public Property lastCompletedStoryHash As Integer
Public Property stats As List(Of Stats)
Public Property customization As Customization
Public Property grimoireScore As Integer
Public Property peerView As PeerView
Public Property genderType As Integer
Public Property classType As Integer
Public Property buildStatGroupHash As Object
End Class
Public Class LevelProgression
Public Property dailyProgress As Integer
Public Property weeklyProgress As Integer
Public Property currentProgress As Integer
Public Property level As Integer
Public Property istep As Integer
Public Property progressToNextLevel As Integer
Public Property nextLevelAt As Integer
Public Property progressionHash As Integer
End Class
Public Class Character
Public Property characterBase As CharacterBase
Public Property levelProgression As LevelProgression
Public Property emblemPath As String
Public Property backgroundPath As String
Public Property emblemHash As Integer
Public Property characterLevel As Integer
Public Property baseCharacterLevel As Integer
Public Property isPrestigeLevel As Boolean
Public Property percentToNextLevel As Double
End Class
Public Class Buckets
Public Property Invisible As Object()
Public Property Item As Object()
Public Property Currency As Object()
End Class
Public Class Currency
Public Property itemHash As Long
Public Property value As Integer
End Class
Public Class Inventory
Public Property buckets As Buckets
Public Property currencies As Currency()
End Class
Public Class Data
Public Property membershipId As String
Public Property membershipType As Integer
Public Property characters As Character()
Public Property inventory As Inventory
Public Property grimoireScore As Integer
Public Property versions As Integer
End Class
Public Class Response
Public Property data As Data
End Class
Public Class MessageData
End Class
Public Class jChars
Public Property Response As Response
Public Property ErrorCode As Integer
Public Property ThrottleSeconds As Integer
Public Property ErrorStatus As String
Public Property Message As String
Public Property MessageData As MessageData
End Class
Module Backend
Public Sub LoadUserJSON(ByVal GameID, ByVal UserName)
Dim BaseURL As String = "http://www.bungie.net/platform/destiny/"
Dim idURL As String = BaseURL & GameID & "/Stats/GetMembershipIdByDisplayName/" & UserName & "/"
Dim Client As New WebClient
Dim JSON_String As String
JSON_String = Client.DownloadString(idURL)
Dim XmlFolder As String = Application.StartupPath & "\XML\"
Try
My.Computer.FileSystem.WriteAllText(XmlFolder & UserName & ".JSON", JSON_String.ToString, False)
Dim json As JObject = JObject.Parse(JSON_String)
MsgBox(json.SelectToken("Response"))
Dim MembershipID As String = json.SelectToken("Response")
LoadAccountJSON(GameID, UserName, MembershipID)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub LoadAccountJSON(ByVal GameID, ByVal UserName, ByVal MembershipID)
Dim BaseURL As String = "http://www.bungie.net/platform/destiny/"
Dim BaseIconURL As String = "http://www.bungie.net/common/destiny_content/icons/"
Dim XmlFolder As String = Application.StartupPath & "\XML\"
'/Destiny/{membershipType}/Account/{destinyMembershipId}/Character/{characterId}/Inventory/
'/Destiny/{membershipType}/Account/{destinyMembershipId}/
Dim AccountURL As String = BaseURL & GameID & "/Account/" & MembershipID & "/"
Dim json As String = New WebClient().DownloadString(AccountURL)
Dim root As JToken = JToken.Parse(json)
Dim name As String = root.SelectToken("Response.data.characters[0].characterbase[0].characterID")
MsgBox(name)
End Sub
End Module
推荐答案
Please see my past answers:
How To Convert object type to C# class object type[^],
how to conver multi level json data to C# Object?[^],
haw to get data from Cloudant (json document)[^].
Ideally, the best situat ion is the one where you can use Data Contract, but it the JSON schema is already given and cannot be changed (because some JSON file have been created before and should be used), it may not be practical (but probably always possible); then you can use other approaches I mentioned.
-SA
Please see my past answers:
How To Convert object type to C# class object type[^],
how to conver multi level json data to C# Object?[^],
haw to get data from Cloudant (json document)[^].
Ideally, the best situation is the one where you can use Data Contract, but it the JSON schema is already given and cannot be changed (because some JSON file have been created before and should be used), it may not be practical (but probably always possible); then you can use other approaches I mentioned.
-SA
here is a solution using JavaScriptSerializer instead of Json.net. Both JavaScriptSerializer and json.net can be used interchangebly. here is the code
here is a solution using JavaScriptSerializer instead of Json.net. Both JavaScriptSerializer and json.net can be used interchangebly. here is the code
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer
Dim jc As Class1.jChars 'Class1.jchars is the root class you have provided
Dim JSON_String As String = "the json file string"
'I use JavaScriptSerializer instead of json.net, both has it's pro and cons
jc = jss.Deserialize(Of Class1.jChars)(JSON_String)
'now that you have got the json string deserialized to jc, you can use its value as you like
End Sub
if the classes you have created matches that of the json file then the above code should work. I have been using a lots of Json recently.
Hope it helps.
if the classes you have created matches that of the json file then the above code should work. I have been using a lots of Json recently.
Hope it helps.
这篇关于vb.net json.net反序列化长json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!