以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何判断JToken的类型?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=193434)

--  作者:zyl19810322
--  发布时间:2024/9/13 11:46:00
--  [求助]如何判断JToken的类型?
Dim json As String = "{""name"":""John Doe"",""age"":30,""isEmployed"":true,""skills"":[""C#"",""VB.NET"",""SQL""],""address"":{""street"":""123 Main St"",""city"":""Anytown"",""zip"":""12345""}}"
Dim jo As JObject = JObject.Parse(json)
For Each it As JToken In jo.Children 
        Output.Show(it.Type)
Next
以上代码输出全部为4,明明有JTokenType.Object,JTokenType.Array,JTokenType.Property

--  作者:有点蓝
--  发布时间:2024/9/13 12:02:00
--  
Dim json As String = "{""name"":""John Doe"",""age"":30,""isEmployed"":true,""skills"":[""C#"",""VB.NET"",""SQL""],""address"":{""street"":""123 Main St"",""city"":""Anytown"",""zip"":""12345""}}"
Dim jo As JObject = JObject.Parse(json)
For Each it As Object In jo 
    Output.Show(it.value.Type)
Next

For Each item As JTokenType In [Enum].GetValues(GetType(JTokenType))
    Output.Show(item & "-" & item.Tostring())
Next

--  作者:zyl19810322
--  发布时间:2024/9/13 12:06:00
--  
谢谢