如何把json代码转换成string字符串?
用.net转换
需要引用json2.js文件 https://github.com/douglascrockford/JSON-js
var arr=[{id:'id',name:'Spring'},{id:'id2',name:'Jane'}];
var str=JSON.stringify(arr);
请问,可不可以用.NET转换?
@慌:
using System.Runtime.Serialization.Json; using System.Web.Script.Serialization; public static string GetJson(object obj) { JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize(obj); }
@无影飞絮剑: 我缺一个引用,补上就好,谢了
Newtonsoft.Json.dll 能帮到你
nuget 搜索Newtonsoft.Json