【发布时间】:2021-03-26 02:07:01
【问题描述】:
我能够读取 json 文件并将其存储在 JObject 变量中。我需要检查空值并忽略任何具有空值的段。我正在考虑循环遍历 JObject,但我不知道如何访问下面 json 中的每个段/键。
我认为我们可以根据我在这里看到的另一个问题像这样循环:
foreach (var x in example) //example is the JObject in which json file is stored
{
string name = x.Key;
JToken value = x.Value;
}
但我的 json 没有密钥。我如何进入每个细分市场并检查名称、描述值是否不为空?
我的 json 是:
{
"lorem ipsum Segment Groups":[
{
"name":"lorem ipsum",
"description":"lorem ipsum",
"segments":[
"Not Enrolled",
"Started Enrollment – Zipcode Lookup",
"Started Enrollment – Passed Flow Step 1",
"Started Enrollment – Passed Flow Step 2"
]
},
{
"name":"lorem ipsum",
"description":"Status Description",
"segments":[
"Moving in next 30 days",
"Moving in next 90 days",
"Not Moving"
]
},
{
"name":"lorem ipsum",
"description":"Interest description",
"segments":[
"Interested - Lots of Time Reading Many Pages",
"Interested - Lots of Time Comparing Products/Prices"
]
}
]
}
谢谢
【问题讨论】:
-
那个 json 中的 null 是什么?
-
请在您的问题中提供有效的 JSON。
-
抱歉,已更正。上面的 json 只是一个应用程序输出的示例。其中的某些段可能为空。
标签: c# json asp.net-core .net-core json.net