我得到了一种接收jproperty数组的方法。这可以是简单的字符串阵列:(" img1.png"," img2.png" ect)。或带有对象的数组:
{[{
"id": "1",
"name": "name",
"image": "img1.png"},{
"id": "2",
"name": "name",
"image": "img2.png"},
{
"id": "3",
"name": "name",
"image": "img3.png"
}]}"
在接收Jproperty的不同动作的方法中需要发生,但是我无法获得if statement来滤除对象事件。
这是我的代码:
private static void handleArray(JProperty array)
{
foreach (JArray x in array)
{
JTokenType type = x.Type;
if (type == JTokenType.Object)
{
Console.WriteLine("Array with objects!");
}
else {
foreach (string childrensTokens in x)
//Array with normal strings
Console.WriteLine(childrensTokens);
}
}
}
(其他语句也崩溃了ATM,因为它也会收回对象。)有人知道如何帮助我吗?我试图去找儿童斯托动物,但失败了。
用:
修复了它 private static void handleArray(JProperty array)
{
//voor de gewone array:
foreach (JArray x in array)
{
foreach (var a in x)
if(a.Type == JTokenType.Object)
{
Console.WriteLine("Array with objects!");
}
else
{
Console.WriteLine((string) a);
}
}