【VB.NET】这个json怎么解析??用的是Newtonsoft.Json.dll
{"objects":{"minecraft/sounds/entity/rabbit/attack2.ogg":{"hash":"4b90ff3a9b1486642bc...
{
"objects": {
"minecraft/sounds/entity/rabbit/attack2.ogg": {
"hash": "4b90ff3a9b1486642bc0f15da0045d83a91df82e",
"size": 7268
},
"minecraft/sounds/entity/shulker/close5.ogg": {
"hash": "e555fcece121879fe0becbada9d01dea27ab153d",
"size": 5376
},
"minecraft/lang/ga_IE.lang": {
"hash": "a108f19142820b3573a658d40950ba3317b65c15",
"size": 142847
},
"minecraft/sounds/mob/horse/leather.ogg": {
"hash": "20abaa7d3b0baa105bc6023d5308f1e5d76acc41",
"size": 11577
},
后面省略
}
用json("objects")(i)("hash")的话会报
Accessed JObject values with invalid key value: 0. Object property name expected.
(i是为了循环获取每项的hash,把i换成minecraft/sounds/mob/horse/leather.ogg等的话可以读取到hash) 展开
"objects": {
"minecraft/sounds/entity/rabbit/attack2.ogg": {
"hash": "4b90ff3a9b1486642bc0f15da0045d83a91df82e",
"size": 7268
},
"minecraft/sounds/entity/shulker/close5.ogg": {
"hash": "e555fcece121879fe0becbada9d01dea27ab153d",
"size": 5376
},
"minecraft/lang/ga_IE.lang": {
"hash": "a108f19142820b3573a658d40950ba3317b65c15",
"size": 142847
},
"minecraft/sounds/mob/horse/leather.ogg": {
"hash": "20abaa7d3b0baa105bc6023d5308f1e5d76acc41",
"size": 11577
},
后面省略
}
用json("objects")(i)("hash")的话会报
Accessed JObject values with invalid key value: 0. Object property name expected.
(i是为了循环获取每项的hash,把i换成minecraft/sounds/mob/horse/leather.ogg等的话可以读取到hash) 展开
1个回答
展开全部
先如下程序集
Imports System.Web.Script.Serialization
Function StringToObject(content As String) As Object
Dim jss As New JavaScriptSerializer()
Return jss.DeserializeObject(content)
End Function
Dim test1 As Dictionary(Of String, Object) = StringToObject("{
" & Chr(34) & "objects" & Chr(34) & ": {
" & Chr(34) & "minecraft/sounds/entity/rabbit/attack2.ogg" & Chr(34) & ": {
" & Chr(34) & "hash" & Chr(34) & ": " & Chr(34) & "4b90ff3a9b1486642bc0f15da0045d83a91df82e" & Chr(34) & ",
" & Chr(34) & "size" & Chr(34) & ": 7268
},
" & Chr(34) & "minecraft/sounds/entity/shulker/close5.ogg" & Chr(34) & ": {
" & Chr(34) & "hash" & Chr(34) & ": " & Chr(34) & "e555fcece121879fe0becbada9d01dea27ab153d" & Chr(34) & ",
" & Chr(34) & "size" & Chr(34) & ": 5376
},
" & Chr(34) & "minecraft/lang/ga_IE.lang" & Chr(34) & ": {
" & Chr(34) & "hash" & Chr(34) & ": " & Chr(34) & "a108f19142820b3573a658d40950ba3317b65c15" & Chr(34) & ",
" & Chr(34) & "size" & Chr(34) & ": 142847
},
" & Chr(34) & "minecraft/sounds/mob/horse/leather.ogg" & Chr(34) & ": {
" & Chr(34) & "hash" & Chr(34) & ": " & Chr(34) & "20abaa7d3b0baa105bc6023d5308f1e5d76acc41" & Chr(34) & ",
" & Chr(34) & "size" & Chr(34) & ": 11577
}}
}
")
Dim cc As Dictionary(Of String, Object) = DirectCast(test1.Values(0), Dictionary(Of String, Object))
Dim dd = cc.Values(0)("hash")
这样就可以遍历 hash值了
追问
是可以历遍了,但是怎么获取objects下的Count呢
追答
Dim Count As Integer = cc.Count
这样就是objects下的Count
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询