嘿,我需要帮助反序列化:
{ "success": true, "rgInventory": { "2722309060": { "id": "2722309060", "classid": "939801430", "instanceid": "188530139", "amount": "1", "pos": 1 }, "2722173409": { "id": "2722173409", "classid": "937254203", "instanceid": "188530139", "amount": "1", "pos": 2 }, "2721759518": { "id": "2721759518", "classid": "720293857", "instanceid": "188530139", "amount": "1", "pos": 3 }, "2721748390": { "id": "2721748390", "classid": "310777652", "instanceid": "480085569", "amount": "1", "pos": 4 } } }最后它应该看起来像:
2722309060#2722173409#2721759518#2721748390
Dim result = JsonConvert.DeserializeObject(jsonstring) 'deserialize it Dim tempfo As String = result("rgInventory").ToString 'get rgInventory Console.WriteLine(tempfo)我如何反序化所有'id'?
Hey I need help in deserializing this:
{ "success": true, "rgInventory": { "2722309060": { "id": "2722309060", "classid": "939801430", "instanceid": "188530139", "amount": "1", "pos": 1 }, "2722173409": { "id": "2722173409", "classid": "937254203", "instanceid": "188530139", "amount": "1", "pos": 2 }, "2721759518": { "id": "2721759518", "classid": "720293857", "instanceid": "188530139", "amount": "1", "pos": 3 }, "2721748390": { "id": "2721748390", "classid": "310777652", "instanceid": "480085569", "amount": "1", "pos": 4 } } }at the end it should look like:
2722309060#2722173409#2721759518#2721748390
Dim result = JsonConvert.DeserializeObject(jsonstring) 'deserialize it Dim tempfo As String = result("rgInventory").ToString 'get rgInventory Console.WriteLine(tempfo)how i can deserialize all 'id's?
最满意答案
json包含项目词典,您想要的ID是键。 如果你反序列化它,你可以从字典中获取它们。 否则,您可以使用JParse和linq来获取它们:
Dim jstr As String = ... ' parse the json Dim js As JObject = JObject.Parse(jstr) ' extract the inventory items Dim ji As JObject = JObject.Parse(js("rgInventory").ToString) ' get and store the keys Dim theIds As List(Of String) = ji.Properties.Select(Function(k) k.Name).ToList()我怀疑当"success"为假时,结果项目列表将为空。 测试它的工作原理:
For Each s As String In theIds Console.WriteLine(s) Next结果:
2722309060 2722173409 2721759518 2721748390
The json contains a Dictionary of items, the IDs you want are the keys. If you deserialized it, you could get them from the Dictionary. Otherwise, you can use JParse and linq to get them:
Dim jstr As String = ... ' parse the json Dim js As JObject = JObject.Parse(jstr) ' extract the inventory items Dim ji As JObject = JObject.Parse(js("rgInventory").ToString) ' get and store the keys Dim theIds As List(Of String) = ji.Properties.Select(Function(k) k.Name).ToList()I suspect that when "success" is false that the resulting items list will be empty. Test that it works:
For Each s As String In theIds Console.WriteLine(s) NextResult:
2722309060 2722173409 2721759518 2721748390
更多推荐
发布评论