本文介绍了如何检查对象是JProperty还是JArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出两个JToken:
Given the two JTokens:
{ "Users": { "Name": "Carl" } }
和
{ "Users": [ { "Name": "Carl" }, {"Name": "Peter"} ] }
如何确定用户是JProperty还是JObject/JArray?
How can I tell if Users is a JProperty or JObject/JArray?
我需要循环用户
foreach (JObject User in myjobject["Users"]) { ... }
解决方案它就像myjobject ["Users"].GetType()一样简单.但是,这在Watch调试器窗口中不起作用,但在运行时起作用.赫姆普夫.
SolutionIt was as simple as myjobject["Users"].GetType(). However, that didn't work in the Watch debugger window, but it worked at runtime. Hrmpff.
推荐答案
Type 属性将告诉您所拥有令牌的类型.
The Type property will tell you the type of the token you have.
switch(token.Type)
{
case JTokenType.Array:
break;
case JTokenType.String:
break;
}
这篇关于如何检查对象是JProperty还是JArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!