C#, JSON Parsing, dynamic variable. How to check type? -
i'm parsing json texts. array
, object
types in text. tried check type follows:
dynamic obj = jsonconvert.deserializeobject(text); //json text if (obj array) { console.writeline("array!"); } else if (obj object) { console.writeline("object!"); }
i checked types while debugging. obj
had type
property object
when parsing objects , array
when parsing arrays. console output object!
both situations. i'm checking type in wrong manner. correct way check type?
edit
json contents:
[ {"ticket":"asd", ...}, {..} ]
or { "asd":{...}, "sdf":{...} }
in both situations output object!
.
edit#2
i changed typechecking order @houssem suggested. still same output. therefore changed op well. code right now, , still same result.
try this, since json.net return object of type jtoken
if (((jtoken)obj).type == jtokentype.array) { console.writeline("array!"); } else if (((jtoken)obj).type == jtokentype.object) { console.writeline("object!"); }
Comments
Post a Comment