Using System.Json to convert C# Arrays and Objects to a JSON string

梦想的初衷 提交于 2019-12-08 00:35:02

问题


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];

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/5399506/using-system-json-to-convert-c-sharp-arrays-and-objects-to-a-json-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!