如何以JSON格式在文本文件中编写List输出 [英] How to write List output in a text file in JSON Format

查看:524
本文介绍了如何以JSON格式在文本文件中编写List输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试写一个列表<>以JSON格式输出文本文件。

有人建议我这样做。



先谢谢。

Hello,

I am trying to write a list<> output in a text file in JSON format.
Con somebody suggest me the way to do so.

Thanks in Advance.

推荐答案

您可以使用

You Can construct the JSON object for the list by using
System.Web.Script.Serialization.JavaScriptSerializer jSearializer = 
                   new System.Web.Script.Serialization.JavaScriptSerializer();
string jsonData = jSearializer.Serialize(userList);//userList means your list<> object



现在可以使用


Now you can write jsonData to the file using

System.IO.File.AppendAllText(@"C:\Output.txt",jsonData);// You can use your own file path here


List<object> mylist;

string json = mySerializerOfChoiceToJSON(mylist); // replace this with the serializer you want
File.WriteAllText("filename.ext", json); // set your file name here


这篇关于如何以JSON格式在文本文件中编写List输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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