3

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

GoBeavs
  • 499
  • 2
  • 10
  • 25
  • good question=>better answers – L.B Nov 20 '12 at 21:01
  • Your issue is that object doesn't have the members that are in the json if you want to convert to an object without making all the members in a costum class use the dynamic keyword: js.Deserialize(json) – Svexo Nov 20 '12 at 21:04

1 Answers1

3

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\"}]"
tcbrazil
  • 1,315
  • 12
  • 25