[英]How to Select JObject in C#
I Have Json Like this 我有这样的杰森
{
"operation": {
"result": {
"message": "Request Details fetched successfully",
"status": "Success"
},
"Details": [
{
"Name" : "Ezio",
"NOTIFICATION STATUS": "OKOC",
},
{
"Name" : "Altair",
"NOTIFICATION STATUS": "OKOC",
},
}
and at first i want to convert this json into csv file but it says json cant start from Object and need to be array, as can you see i need to get rid of operation so i will get Details Only. 首先,我想将此json转换为csv文件,但它说json不能从Object开始并且需要为数组,如您所见,我需要摆脱操作,因此我将仅获得Details。
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
JObject Line2 = JObject.Parse(responseString);
JArray array = (JArray)Line2["Details"];
so i tried with that code above but it shows error message Object reference not set to an of an Object "array was null"
so its look like i didnt get anything from array because its null? 所以我尝试了上面的代码,但是显示错误消息Object reference not set to an of an Object "array was null"
因此它看起来像我没有从数组中得到任何东西,因为它为空? anyone can help me here thanks 任何人都可以在这里帮助我,谢谢
As @ruhul mentioned in his comment I was able to retrive Details
using following code: 正如@ruhul在他的评论中提到的,我能够使用以下代码检索Details
:
JArray array = (JArray)line2["operation"]["Details"];
With the following JSON: 使用以下JSON:
{
"operation": {
"result": {
"message": "Request Details fetched successfully",
"status": "Success"
},
"Details": [
{
"Name": "Ezio",
"NOTIFICATION STATUS": "OKOC"
},
{
"Name": "Altair",
"NOTIFICATION STATUS": "OKOC"
}
]
}
}
Output: 输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.