简体   繁体   English

解析包含未命名节点的JSON

[英]Parse JSON containing unnamed node

I have the following JSON payload. 我有以下JSON有效负载。

The challenge is to fetch the name value and the corresponding root node number (3925 or 3932) since this node is unnamed. 挑战在于获取名称值和相应的根节点编号(3925或3932),因为该节点未命名。

I am using C# 我正在使用C#

"3925": {
        "totalExecutions": 2,
        "endDate": "",
        "description": "",
        "totalExecuted": 2,
        "started": "",
        "versionName": "Custom Pipes Development",
        "expand": "executionSummaries",
        "projectKey": "WUSDV007",
        "versionId": 22361,
        "environment": "",
        "totalCycleExecutions": 2,
        "totalDefects": 0,
        "build": "",
        "createdBy": "mghosh",
        "ended": "",
        "name": "SetMaxFutureDateFromCustomerField_Mobile",
        "totalFolders": 0,
        "modifiedBy": "mghosh",
        "projectId": 17101,
        "createdByDisplay": "Mayukh Ghosh",
        "startDate": "",
        }
    }

"3932": {
        "totalExecutions": 2,
        "endDate": "",
        "description": "",
        "totalExecuted": 2,
        "started": "",
        "versionName": "Custom Pipes Development",
        "expand": "executionSummaries",
        "projectKey": "WUSDV007",
        "versionId": 22361,
        "environment": "",
        "totalCycleExecutions": 2,
        "totalDefects": 0,
        "build": "",
        "createdBy": "nkonda",
        "ended": "",
        "name": "WUSDV007-29779-Fee Validation",
        "totalFolders": 0,
        "modifiedBy": "nkonda",
        "projectId": 17101,
        "createdByDisplay": "Naveen Kumar Konda",
        "startDate": "",

    }

Any suggestions are highly appreciated. 任何建议都将受到高度赞赏。

Try code as follows: 尝试如下代码:

string jsonString = "{\"3925\": { \"totalExecutions\": 2, \"endDate\": \"\", \"description\": \"\", \"totalExecuted\": 2, \"started\": \"\", \"versionName\": \"Custom Pipes Development\", \"expand\": \"executionSummaries\", \"projectKey\": \"WUSDV007\", \"versionId\": 22361, \"environment\": \"\", \"totalCycleExecutions\": 2, \"totalDefects\": 0, \"build\": \"\", \"createdBy\": \"mghosh\", \"ended\": \"\", \"name\": \"SetMaxFutureDateFromCustomerField_Mobile\", \"totalFolders\": 0, \"modifiedBy\": \"mghosh\", \"projectId\": 17101, \"createdByDisplay\": \"Mayukh Ghosh\", \"startDate\": \"\" }}";

var parameters = JObject.Parse(jsonString);

foreach (var item in parameters.OfType<JProperty>())
{
   var innerObject = JObject.Parse(item.Value.ToString());
   Console.WriteLine(innerObject.ToString());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM