【发布时间】:2018-02-27 03:28:43
【问题描述】:
我有一个接收 JProperty 数组的方法。 这可以是一个简单的字符串数组:(“Img1.png”、“Img2.png”等)。或带有对象的数组:
{[{
"id": "1",
"name": "name",
"image": "img1.png"},{
"id": "2",
"name": "name",
"image": "img2.png"},
{
"id": "3",
"name": "name",
"image": "img3.png"
}]}"
在接收 JProperty 的不同操作的方法中需要发生,但我无法获取 if 语句来过滤对象太对象事件。
这是我目前的代码:
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);
}
}
}
(else 语句使 atm 崩溃,因为它也接收对象。) 有谁知道如何帮助我?我试图到达 childrensTokens 但失败了。
【问题讨论】:
-
foreach (JArray x in array)???JProperty中没有JArray -
我对 Json 和 c# 都很陌生,下面我回答了我是如何使它工作的,但我愿意接受反馈等 x]
标签: c# .net json types json.net