Search code examples
c#jsonjson.net

json.net has key method?


If my response has key "error" I need to process error and show warning box.

Is there "haskey" method exists in json.net? Like:

var x= JObject.Parse(string_my);
if(x.HasKey["error_msg"])
    MessageBox.Show("Error!")

Solution

  • Just use x["error_msg"]. If the property doesn't exist, it returns null.