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 ...
 
随机推荐
- mysql的压缩版安装
			
MYSQL压缩版 自己建立: data(位于mysql的bin一层文件夹),my.ini(文本) my.ini(下面是文本内容) [client] port=3306 default-characte ...
 - List自定义排序 (例子省份排序)
			
//待排序集合 List<String> list=new ArrayList<String>(); list.add("辽宁"); list.add(&q ...
 - umake ide -h
			
umake ide -husage: umake ide [-h] {netbeans,idea,clion,eclipse,atom,idea-ultimate,ec ...
 - requests快速构造请求头的方法
			
上图请求头内容,内容多不说,也不确认哪些数据是必须的,网上找到一个懒办法 快速一键生成 Python 爬虫请求头 实战演练 抓取网站:https://developer.mozilla.org... ...
 - 深入Java类加载全流程,值得你收藏
			
先测试一番,全对的就走人 //题目一 class Parent1{ public static String parent1 = "hello parent1"; static { ...
 - Linux文件和目录的属性及权限总结
			
本文讲述的是文件或目录的属性及权限,比如索引节点inode.文件类型.文件权限及属主:还对setuid.setgid及粘贴位进行了相关的讲解.其中,对ln.chmod.chown.chgrp.umas ...
 - 在sublime text 3中搭建Java开发环境
			
在jdk bin目录下新建一个bat文件: 如D:\JAVA\jdk1.8.0_65\bin\runJava.bat @ECHO OFF cd %~dp1 ECHO Compiling %~nx1.. ...
 - Windows API 教程(九) 网络编程
			
茵蒂克丝 基础概念 ip 地址 服务端与客户端 Socket 基础概念 头文件和库文件 常用函数 WSAStartup ( ) 函数 WSACleanup ( ) 函数 Socket ( ) 函数 c ...
 - VC运行时库/MD、/MDd、/MT、/MTd说明
			
http://blog.csdn.net/holybin/article/details/26134153 VC运行时库设置:VC项目属性->配置属性->C/C++->代码生成-&g ...
 - LUA学习笔记(第5-6章)
			
x = a or b 如果a为真则x = a 如果a为假则x = b print(a .. b) 任何非nil类型都会被连接为字符串,输出 多重返回值 local s,e = string.find( ...