Invalid Json primitives

Could you help me in solving this problem. I have one asp.net application, in this I use the Javascript serializer to serialize the dataset and then convert to a list. This code is shown below.

JavaScriptSerializer json = new JavaScriptSerializer(); strJson = json.Serialize(aclDoc); 

But during deserialization, I got one ArguementException, like Invalid Json Primitives, with my Json value. My json value

 [{"Id":"F79BA508-F208-4C37-9904-DBB1DEDE67DB","App_Id":"ScriptFlow","Name":"New form","FriendlyName":"","Read":"Revoke","ReadRule":"a353776f-cbdc-48b7-a15b-4a2316d19b05","Update":"Grant","UpdateRule":"be30c34e-33ec-4c0a-9f09-4fd483f5f1b9","Create":"Revoke","CreateRule":"898dce4d-4709-45b6-8942-d7efb07cbd86","Delete":"Revoke","DeleteRule":"aa14d435-dec8-4ade-ad9b-830ae5ee15d0"}][{"Id":"1","Doc_Id":"858E013C-5775-4FDF-AA1E-2C84053EE39F","Name":"TextBox1","FriendlyName":"TextBox1","Read":"Grant","ReadRule":"0a2e3c0e-ad8f-4f75-9160-cfd9827ac894","Update":"Grant","UpdateRule":"ecad3cf4-104f-44dc-b815-de039f3a0396"},{"Id":"2","Doc_Id":"858E013C-5775-4FDF-AA1E-2C84053EE39F","Name":"TextBox2","FriendlyName":"TextBox2","Read":"Grant","ReadRule":"81e0e9ef-09f7-4c25-a58e-d5fdfbd4c2ba","Update":"Grant","UpdateRule":"2047f662-c881-413b-a1f9-69f15bf667fc"}] 

Deserialization Code:

 JavaScriptSerializer json = new JavaScriptSerializer(); lstDoc = json.Deserialize<List<ACLDocument>>(value); return lstDoc; 

where lstDoc is a List Collection of type of my class

I got an exception:

 Invalid JSON primitive: {"Id":"1","Doc_Id":"858E013C-5775-4FDF-AA1E-2C84053EE39F","Name":"TextBox1","FriendlyName":"TextBox1","Read":"Grant","ReadRule":"0a2e3c0e-ad8f-4f75-9160-cfd9827ac894","Update":"Grant","UpdateRule":"ecad3cf4-104f-44dc-b815-de039f3a0396"},{"Id":"2","Doc_Id":"858E013C-5775-4FDF-AA1E-2C84053EE39F","Name":"TextBox2","FriendlyName":"TextBox2","Read":"Grant","ReadRule":"81e0e9ef-09f7-4c25-a58e-d5fdfbd4c2ba","Update":"Grant","UpdateRule":"2047f662-c881-413b-a1f9-69f15bf667fc"}]. 

Please help me solve this problem. thanks in advance

+6
json c # serialization javascriptserializer
source share
4 answers

Your input line is really a wrong JSON string. The entry consists of two valid JSON strings:

 [ { "Id": "F79BA508-F208-4C37-9904-DBB1DEDE67DB", "App_Id": "ScriptFlow", "Name": "New form", "FriendlyName": "", "Read": "Revoke", "ReadRule": "a353776f-cbdc-48b7-a15b-4a2316d19b05", "Update": "Grant", "UpdateRule": "be30c34e-33ec-4c0a-9f09-4fd483f5f1b9", "Create": "Revoke", "CreateRule": "898dce4d-4709-45b6-8942-d7efb07cbd86", "Delete": "Revoke", "DeleteRule": "aa14d435-dec8-4ade-ad9b-830ae5ee15d0" } ] 

and

 [ { "Id": "1", "Doc_Id": "858E013C-5775-4FDF-AA1E-2C84053EE39F", "Name": "TextBox1", "FriendlyName": "TextBox1", "Read": "Grant", "ReadRule": "0a2e3c0e-ad8f-4f75-9160-cfd9827ac894", "Update": "Grant", "UpdateRule": "ecad3cf4-104f-44dc-b815-de039f3a0396" }, { "Id": "2", "Doc_Id": "858E013C-5775-4FDF-AA1E-2C84053EE39F", "Name": "TextBox2", "FriendlyName": "TextBox2", "Read": "Grant", "ReadRule": "81e0e9ef-09f7-4c25-a58e-d5fdfbd4c2ba", "Update": "Grant", "UpdateRule": "2047f662-c881-413b-a1f9-69f15bf667fc" } ] 

but you cannot concatenate two JSON strings. To say exactly what you get after such concatenation in nothing more than a JSON string.

I recommend you check out the JSON strings at http://www.jsonlint.com/ . Just cut and paste the data you want to verify, and click the "Check" button.

+4
source share

To answer the question directly, since everyone thinks that this is a Microsoft forum and not responding directly.

The string is sent as an array of 2 elements. You forgot the "[" at the beginning of the line, which means that the values ​​contained are the structure of the array.

Insert '[' at the beginning of the line and the error should go away.

+3
source share

This is a useful tool to examine your JSON objects:

http://jsonviewer.codeplex.com/

0
source share

See if you have any // or commented out lines in project.json Removing this solution solved the same problem for me

0
source share

All Articles