c#怎么返回一个json数据类型
1个回答
展开全部
使用newtonsoft.json.dll
public static string ObjectToJson(object obj)
{
JsonSerializerSettings setting = new JsonSerializerSettings();
setting.CheckAdditionalContent = false;
setting.NullValueHandling = NullValueHandling.Ignore;
setting.ObjectCreationHandling = ObjectCreationHandling.Reuse;
string jsonString = JsonConvert.SerializeObject(obj, Formatting.None, setting);
return jsonString;
}
可以返回一个json字符串
public static string ObjectToJson(object obj)
{
JsonSerializerSettings setting = new JsonSerializerSettings();
setting.CheckAdditionalContent = false;
setting.NullValueHandling = NullValueHandling.Ignore;
setting.ObjectCreationHandling = ObjectCreationHandling.Reuse;
string jsonString = JsonConvert.SerializeObject(obj, Formatting.None, setting);
return jsonString;
}
可以返回一个json字符串
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询