How to read JSON into a JObject when the string contains double quotes ?

I have a piece of JSON that I want to get into a string for C# to use. The problem is when I escape all the double quotes it seems no longer valid. For example:

 string jsonString = " {[ {    \"FieldId\": \"Fields.364\",    \"FieldName\": \"LoanNo\",    \"Precision\": \"0\"  } ,  {    \"FieldId\": \"Fields.4002\",    \"FieldName\": \"LastNameB\"  } ]}";
        JObject jsettings = JObject.Parse(jsonString);

Is there a easier way to get a string of JSON into a C# JObject?

Jon Skeet
people
quotationmark

You're not actually escaping any of the double quotes, as far as the JSON is concerned - the string doesn't contain any backslashes. You can confirm that with Console.WriteLine(jsonString);.

The problem is that you've currently got an array directly inside an object - that's not valid JSON.

If you change it so that the array is a property, it's fine:

string jsonString = " { \"foo\":[ { /* rest as before */ } ] }";

That ended up as JSON of:

{
  "foo": [
    {
      "FieldId": "Fields.364",
      "FieldName": "LoanNo",
      "Precision": "0"
    },
    {
      "FieldId": "Fields.4002",
      "FieldName": "LastNameB"
    }
  ]
}

(Just using Console.WriteLine(jsettings); after the code you'd posted.)

people

See more on this question at Stackoverflow