Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScriptSerializer Invalid JSON primitive

When I use the JavaScriptSerializer in C# I'm getting a "Invalid JSON primitive" exception. I assume the issue is with my json input string but I don't see the problem.

JavaScriptSerializer  new JavaScjs =riptSerializer();
js.Deserialize<Object>(json)

"{\"new_name\":\"Arlington\",\"new_locationid\":\"089c6c6a-f520-e111-bdd3-00505695001f\"},{\"new_name\":\"Atlanta\",\"new_locationid\":\"0a9c6c6a-f520-e111-bdd3-00505695001f\"},{\"new_name\":\"Baltimore\",\"new_locationid\":\"0c9c6c6a-f520-e111-bdd3-00505695001f\"}"

like image 695
GoBeavs Avatar asked Mar 13 '26 05:03

GoBeavs


1 Answers

GoBeavs:

I validated your json here: http://jsonlint.com/

Your json text is wrong: you must enclose it with brackets ([]) when you have an array of json's. It must looks like this:

"[{\"new_name\":\"Arlington\",\"new_locationid\":\"089c6c6a-f520-e111-bdd3-00505695001f\"},{\"new_name\":\"Atlanta\",\"new_locationid\":\"0a9c6c6a-f520-e111-bdd3-00505695001f\"},{\"new_name\":\"Baltimore\",\"new_locationid\":\"0c9c6c6a-f520-e111-bdd3-00505695001f\"}]"
like image 118
tcbrazil Avatar answered Mar 14 '26 19:03

tcbrazil