为JToken生成键值

时间:2012-08-21 19:39:24

标签: c# json key-value

我有键值JToken,服务器发送给我。我如何通过json.net做同样的事情?

示例:

{
  "1_type": "sound",
  "1url": "http://example.com/sound.mp3",
  "2_type": "url",
  "2url": "http://example.com",
}

1 个答案:

答案 0 :(得分:3)

使用Json.Net

JObject jObj = new JObject();
jObj["1_type"] = "sound";
jObj["1url"] = "http://example.com/sound.mp3";
jObj["2_type"] = "url";
jObj["2url"] = "http://example.com";
var jsonString = jObj.ToString();