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的更多相关文章

  1. [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  2. [LeetCode] Serialize and Deserialize Binary Tree 二叉树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  3. 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 ...

  4. Leetcode: Serialize and Deserialize BST

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  5. [LeetCode] Serialize and Deserialize Binary Tree

    Serialize and Deserialize Binary Tree Serialization is the process of converting a data structure or ...

  6. LeetCode——Serialize and Deserialize Binary Tree

    Description: Serialization is the process of converting a data structure or object into a sequence o ...

  7. Serialize and Deserialize Binary Tree

    Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...

  8. 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 ...

  9. 297. Serialize and Deserialize Binary Tree

    题目: Serialization is the process of converting a data structure or object into a sequence of bits so ...

随机推荐

  1. Python-直接存储类实例作为序列的元素

    如果我们需要存储的数据有很多属性,并且存储的数量很多,可选择定义一个类来表示数据类型,而类的实体作为单个的成员进行存储,这样做的好处是可以只存储一个容器,而不需要每次都存储大量的数据,并且可以限制对数 ...

  2. Python学习,第四课 - 字符串相关操作

    这次主要说说Python中字符串的使用方法详解 capitalize 首字母大写 print('chengshou'.capitalize()) #输出结果:Chengshou title 修改成标题 ...

  3. latex2e

    classs and packages 这一节介绍新的latex文档结构, 以及新的文件类型: classs and packages 类和包是什么? lext 2.09和latex2e的主要差别就在 ...

  4. ios---二维码的扫描

    二维码扫描 使用ios的AVFoundation框架实现二维码扫描 第一步:设置相机访问权限:在Info.plist添加Privacy - Camera Usage Description权限 第二步 ...

  5. vue响应式原理的实现

    响应式实现的原理---如何监控数据的变化:两种方法 Vue 2.x defineProperty(es5) Vue 3.x Proxy(es6) 语法:Object.defineProperty(参数 ...

  6. (.text+0x18): undefined reference to `main'

    在将VS中的程序移植到ubuntu中出现的一个问题,主要原因是在vs中默认的主函数写成int _tmain(), 而在gcc编译时要找的是int main().改过来就可以了.

  7. Docker Mysql部署与使用

    参考链接:Docker 安装 Mysql 详解

  8. ros机器人之动作(二)

    前面我们实现了动作的定义,接下来实现动作的功能 实现一个基本的动作服务器 准备好所需的动作定义后就可以开始编写代码了.动作和话题一样,都是使用回调机制,即回调函数会在收到消息时被唤醒和调用. 例:si ...

  9. python笔记18(复习)

    今日内容 复习 内容详细 1.Python入门 1.1 环境的搭建 mac系统上搭建python环境. 环境变量的作用:方便在命令行(终端)执行可执行程序,将可执行程序所在的目录添加到环境变量,那么以 ...

  10. 🔥SpringBoot图文教程2—日志的使用「logback」「log4j」

    有天上飞的概念,就要有落地的实现 概念+代码实现是本文的特点,教程将涵盖完整的图文教程,代码案例 文章结尾配套自测面试题,学完技术自我测试更扎实 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例 ...