How to get dynamic key name from json object?

Dear all,
I has a json object as below.

{
“status”: {
“code”: 200,
“message”: “OK”
},
“data”: {
“A”: {
“123”: {
“id”: “1”,
“name”: “name 1”,
“group_id”: “1”,
}

		"124": {
			 "id": "2",
            "name": "name 2",
            "group_id": "1",
				}
				
		"125": {
			 "id": "3",
            "name": "name 3",
            "group_id": "1",
				}
		 }
		}

}

How do I get the dynamic value “123”, “124”, “125”? Please help me.

1 Like

1/ Deserialize the JSON into a JObject variable (e.g. JObj)
2/ Use JObj("data")("A") to get collection of JProperty objects (e.g. JCol)
3/ ForEach object (e.g. JP) in the collection JCol use JP.Name to get name of the property (i.e. 123, 124…)
4/ Use JP.Value.Item("id").ToString to get value of property “id” (i.e. 1, 2…)

For more retals about Newtonsoft JSON framework go to:

EDIT: Sample workflow
json-test.zip (1.9 KB)

Cheers

4 Likes

Where I fond