我有一个 JSON 字符串。我需要替换其中的一些值。我这样做:
string jsonString = "{\"id\": \"5281959998_126883980715630\", \"name\": \"The New York Times\", \"category\": \"Company\"}";
JObject jObj = JObject.Parse(jsonString);
jObj["category"] = "inc";
string strJson = jObj.ToString();
但它不能正常工作!符号“\r\n”出现在每个键值对之后。我究竟做错了什么?如何防止出现这些符号?
最佳答案
使用 ToString()
您无法更改此行为。是documented此方法返回缩进 JSON。
您需要使用 the overload相反:
var result = jObj.ToString(Formatting.None);
关于c# - 使用 JSON.net 库 (C#) 替换 JSON 字符串中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620378/