I have received a JSON data sample that looks like the following. I am looking to perform a certain action based on specific conditions within the response:
If success
is equal to true
and if the length of ParentList
is greater than 0, then execute a logic in C#.
{
"success": "true",
"Building_rjid": "NVMBBD0015609",
"ParentList": [
{
"Site_sap_id": "I-MU-MUMB-ENB-I134",
"Site_GeoCoordinates": "19.01612,73.04158",
"Site_priority": "P1",
"BearingAngleFromBuilding": 278
},
{
"Site_sap_id": "I-MU-MUMB-ENB-7172",
"Site_GeoCoordinates": "19.0138,73.041",
"Site_priority": "P2",
"BearingAngleFromBuilding": 205
},
{
"Site_sap_id": "I-MU-MUMB-ENB-7202",
"Site_GeoCoordinates": "19.01841417,73.043785",
"Site_priority": "P3",
"BearingAngleFromBuilding": 33
}
]
}
UPDATE
This is how I retrieve the JSON response:
try
{
strInputJSON_BldgRJID = (new JavaScriptSerializer()).Serialize(inputBldgRJID);
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
client.Encoding = Encoding.UTF8;
jsonData = client.UploadString(apiUrl_CheckBldg, strInputJSON_BldgRJID); // json response
}