1

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 ???

4
  • you can convert json to C# class here json2csharp.com deserialize it, and check code Commented Dec 25, 2017 at 8:15
  • How about jsonObject["StatusCode"] Commented Dec 25, 2017 at 8:19
  • What's the error you are getting ? Commented Dec 25, 2017 at 8:20
  • tks all ! I can not check StatusCode, I have modified the code above Commented Dec 25, 2017 at 8:32

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.