GoBeavs
GoBeavs

Reputation: 499

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\"}"

Upvotes: 3

Views: 12830

Answers (1)

tcbrazil
tcbrazil

Reputation: 1325

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\"}]"

Upvotes: 3

Related Questions