使用System.Json将C#数组和对象转换为JSON字符串 [英] Using System.Json to convert C# Arrays and Objects to a JSON string

查看:106
本文介绍了使用System.Json将C#数组和对象转换为JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看System.Json,但似乎无法在此处找到将C#数组或类实例转换为JSON字符串的方法.我正在寻找与Objective-c中的SBJSON类似的功能,例如,可以将NSArray转换为JSON字符串,如下所示:

I am looking at System.Json, but can't seem to find methods in here that will allow me to convert a C# array or class instance into a JSON string. I am looking for functionality similar to SBJSON in objective-c where, for example, an NSArray can be converted to a JSON string as follows:

NSString *resultArrayString = [json stringWithObject:resultArray allowScalar:YES error:nil];

继续使用同一示例,在System.Json命名空间中是否存在等效方法,该方法可以将C#字符串数组转换为JSON字符串?

Staying with this same example, is there an equivalent method in System.Json namespace somewhere that would allow convert a C# string array to a JSON string?

推荐答案

System.Json是Json格式的非常轻量级的读写器,它没有为您提供帮助的序列化程序.

System.Json is a very lightweight reader and writer of the Json format, it does not come with a serializer that would do this for you.

需要比System.Json更多功能的人正在使用NewtonSoft的开源Json库.它包括许多高级功能,例如序列化,JsonDocument和许多其他功能.

Folks that want more features than the System.Json are using NewtonSoft's open source Json library. It includes many high level features like serialization, JsonDocument and many more features.

这篇关于使用System.Json将C#数组和对象转换为JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆