简体   繁体   中英

how to read nested json objects in c#

I have json string

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "hits": {
        "total": 78,
        "max_score": 1.5,
        "hits": [{
                "_index": "S3",
                "_type": "se",
                "_id": "00CD03",
                "_score": 1.5,
                "contact": {
                    "defaultAddress": {
                        "addressLine1": "AAAAAAAAAAAAAAA",
                        "addressLine2": null,
                        "addressCode": null,
                        "geoLocation": {
                            "lon": "14.1514",
                            "lat": "16.7555"
                        },
                    },
                    "defaultEmail": "aaaa.bbbb@gmail.in",
                    "defaultPhoneNumber": "080 1140 637",
                }
            }, {
                "_index": "S3",
                "_type": "se",
                "_id": "00C3D0-01260-3",
                "_score": 1.5,
                "contact": {
                    "defaultAddress": {
                        "addressLine1": "bbbbbbbbbb 1",
                        "addressLine2": "ggggggggg",
                        "addressCode": null,
                        "geoLocation": {
                            "lon": "97.1511101",
                            "lat": "15.7888899"
                        },
                    },
                    "defaultEmail": "kkkkk@yahoo.de",
                    "defaultPhoneNumber": "0909 140 637",
                }
            }
        ]
    }
}

need to loop through the json and create a list details in C#. Looking for help

@NLSrini

You can use the nugget package " Newtonsoft.Json ". Then you can create an class Object that represents your JSON structure and to deserialize you can use: JsonConvert.DeserializeObject<YourClass>(json);

You can see for more examples here: https://www.newtonsoft.com/json/help/html/SerializingJSON.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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