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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -