AirBlack
AirBlack

Reputation: 145

How to check the StatusCode in json object to get a string of httpResponse rest API

I can't check StatusCode when REST API and parse JObject

code

string jsonResponse = HttpRequest(HostAPI, "POST", paramModel);
JObject jsonObject = JObject.Parse(jsonResponse);
if (jsonObject["data"] != null && jsonObject["StatusCode"]==200)  ????

jsonResponse

{"data":[{"OBJID":1012540462,"SUPID":1041252952,"STATUSPTC":1.0,"DATEACTIVESUP":0.0}],"StatusCode":200}

I can not check StatusCode

if (jsonObject["StatusCode"]== 200) 
{
   //do something
}

Please help me if you know ???

Upvotes: 1

Views: 2277

Answers (1)

Jeevan
Jeevan

Reputation: 538

jsonObject["StatusCode"] type is Newtonsoft.Json.Linq.JValue

So we have to explicitly cast it.

 if ((int)jsonObject["StatusCode"] == 200)
        {
            Console.WriteLine("working");
        }

You can find working sample here

Upvotes: 1

Related Questions