Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

c# - Parse nested json and return the values as string[]

Can you help me parse the values in 'realEstateProperties' attribute (ex. serial number and economyType.value). Here is a part of the json file:

{
    "Entity1": {
        "id": "5f514d20744a1fb",
        "realEstateProperties": [
            {
                "serialNumber": "11",
                "cadastralSections": [
                    {
                        "id": "5f514dc11a1e3",
                        "economyType": {
                            "value": "landRegisterPage.type",
                        }
                    }
                ],
                "landRegisterPage": {
                    "id": "3456",
                    "landRegisterBook": {
                        "abbreviation": null
                    },
                    "note": "LRP",
                    "tags": null
                },
                "propertyTextBlock": null
            }
        ],
        "customFields": [],

Here is what I currently have:

        public static string[] GetJsonValues(string jsonProperty)
        {
            testCaseName = "Entity1";
            
            FixtureIncident.Root incObject = new FixtureIncident.Root();
            incObject = LoadJSONFile();
            JObject incJson = JObject.FromObject(incObject);
            var attributes = incJson[testCaseName].ToList<JToken>();
            
            var property = attributes.Find(i => i.ToObject<JProperty>().Name == jsonProperty) as JArray;   //returns property=null
            
            string[] Properties = property.ToObject<string[]>();

            return Properties;
        }

property returns null and I am not sure how to correct it. I need to save all the realEstateProperties values in a string[].

I found some similar topics but I couldn't adjust my code so I make it works. Thanks in advance for your help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...