I’ve got a JSON string. I need to replace some values in it. I do it this way:
string jsonString = "{\"id\": \"5281959998_126883980715630\", \"name\": \"The New York Times\", \"category\": \"Company\"}";
JObject jObj = JObject.Parse(jsonString);
jObj["category"] = "inc";
string strJson = jObj.ToString();
But it doesn’t work properly! Symbols “\r\n” appears after each key-value pair. What am I doing wrong? How can I prevent appearance of these symbols?
Using
ToString()you can’t change this behaviour. It is documented that this method returns indented JSON.You need to use the overload instead: