如何使用C#写入JSON文件? [英] How to write to a JSON file using C#?

查看:527
本文介绍了如何使用C#写入JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将用户添加到Users json文件.我正在使用Json.net来执行此操作,任何人都对我可能如何执行此操作有任何想法?

I want to be able to add users to a Users json file. I'm using Json.net to do this, anyone got any ideas of how I might go about doing this?

推荐答案

这是在c#中编写JSON文件的简单方法

Here is a simple way of writing a JSON file in c#

UserData user = Call Method Here

string json = JsonConvert.SerializeObject(user, Formatting.Indented);
File.WriteAllText(@"c:\user.json", json);

这将编写一个简单的JSON文件并将其保存到您的计算机中.

This will write a simple JSON file and save it to your computer.

这篇关于如何使用C#写入JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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