C# NewtonJson Serialize and deserialize
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
using System.Text; namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
DictionaryJsonDemo();
Console.ReadLine();
} static void DictionaryJsonDemo()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
for (int i = ; i < ; i++)
{
string key = Guid.NewGuid().ToString();
dic.Add(key, key);
} var serializedJson = JsonConvert.SerializeObject(dic,Formatting.Indented);
Console.WriteLine("Serialized json:");
Console.WriteLine(serializedJson);
WriteContentToJson(serializedJson);
Dictionary<string, string> deserializedDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(serializedJson);
foreach(var d in deserializedDic)
{
Console.WriteLine($"Key:{d.Key},Value:{d.Value}");
}
} static void WriteContentToJson(string msg)
{
string jsonFile = @"..\..\..\Resource\JsonFile.json";
using(StreamWriter msgWriter=new StreamWriter(jsonFile,false,Encoding.UTF8))
{
msgWriter.WriteLine(msg);
}
}
}
Relative file path @"..\formerdirectory",@"..\..\AboveTwoDir",@"..\..\..\AboveThreeDir";
C# NewtonJson Serialize and deserialize的更多相关文章
- [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [LeetCode] Serialize and Deserialize Binary Tree 二叉树的序列化和去序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- U家面试prepare: Serialize and Deserialize Tree With Uncertain Children Nodes
Like Leetcode 297, Serialize and Deserialize Binary Tree, the only difference, this is not a binary ...
- Leetcode: Serialize and Deserialize BST
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [LeetCode] Serialize and Deserialize Binary Tree
Serialize and Deserialize Binary Tree Serialization is the process of converting a data structure or ...
- LeetCode——Serialize and Deserialize Binary Tree
Description: Serialization is the process of converting a data structure or object into a sequence o ...
- Serialize and Deserialize Binary Tree
Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...
- 449. Serialize and Deserialize BST——几乎所有树的面试题目都会回到BFS或者DFS,使用BFS,None节点存#
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- 297. Serialize and Deserialize Binary Tree
题目: Serialization is the process of converting a data structure or object into a sequence of bits so ...
随机推荐
- 小白学Java:File类
目录 小白学Java:File类 不同风格的分隔符 绝对与相对路径 File类常用方法 常用构造器 创建方法 判断方法 获取方法 命名方法 删除方法 小白学Java:File类 我们可以知道,存储在程 ...
- Vue+elementUI 自定义动态数据菜单导航组件实现展开收缩+路由跳转router-view渲染数据 路由跳转到同一个页面带参数ID 自动刷新数据
准备:导入ElementUI 看官网教程 数据准备:JSON数据转换成树状 参考文章: JS实现 JSON扁平数据转换树状数据 后台我拿的数据是这样的格式: [ {id:1 , parentId: 0 ...
- vscode打开文件,中文显示乱码(已解决)
之前使用vscode打开keil的文件后,发现显示乱码,网上查找资料发现大多是这种方法:将files.autoGuessEncoding改为true,但是并没有用. 发现第二种方法为:在vscode中 ...
- [Ubuntu]解决"系统的网络服务与此版本的网络管理器不兼容"提示
先贴方法: sudo -s ' 获取root权限 apt-get install network-manager ' 重装网络管理器 如果系统提示有升级包可用则安装即可. 开机后,右上角没有网络图标. ...
- 【Nginx入门系列】第二章 外部无法访问Nginx服务器
问题 Nginx服务器已经搭建成功,并且已经启动(如下图所示),并且可以ping通nginx服务器的ip地址,但是外部机子无法访问 Nginx服务器(没法显示欢迎页面) 解决方案 一般这种情况是出现在 ...
- Java 设计模式之抽象工厂模式
抽象工厂模式(Abstract Factory Pattern)是围绕一个超级工厂创建其他工厂.该超级工厂又称为其他工厂的工厂.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 在抽 ...
- Kafka源码工程examples项目配置log4j
examples项目启动想知道有哪些错误,通过日志了解代码执行逻辑,但是启动SimpleConsumerDemo了报错如下: log4j.proproties也配置了 log4j.proproties ...
- LeetCode 18: 4 Sum 寻找4数和
链接 4Sum 难度 Medium 描述 Given an array nums of n integers and an integer target, are there elements a , ...
- BZOJ 3343 教主的魔法(分块)
题意: 有一个1e6的数组,t次操作:将[l,r]内的值增加w,或者查询[l,r]内的值大于等于add的 思路: 分块,块大小为sqrt(n),每次只需要暴力头尾两块,中间的整块打标记, 对于查询查操 ...
- 微信小程序中的图表构建
第一 html中的代码 <view class="container"> <canvas canvas-id="lineCanvas" bin ...