当前位置:网站首页>An example of newtonjason
An example of newtonjason
2022-07-03 12:52:00 【superfreak】
person class The code is as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewTonJSONTest
{
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string[] Mobiles { get; set; }
}
}
The default class of a console program , It's also main Class Program The code is as follows :
using System;
using System.Collections.Generic;
using Newtonsoft.Json;//
using Newtonsoft.Json.Linq;//
namespace NewTonJSONTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
List<Person> person0;
List<Person> person = new List<Person>(){
new Person() {Name = "China Mobile", Age = 30, Mobiles = new string[] {"13800138000","10086"}},
new Person() {Name = "China Telecom", Age = 60, Mobiles = new string[] {"10000","189"}},
new Person() {Name = "China Unicom", Age = 90, Mobiles = new string[] {"10010"}}
};
// Serialize to JSON String
string str_json = JsonConvert.SerializeObject(person);
Console.WriteLine(str_json);
Console.WriteLine(" Serialization is complete , Serialized the object as a json character string ");
// Deserialize to Person List objects , Deserialization is *str_json character string Serialize as an object
person0 = JsonConvert.DeserializeObject<List<Person>>(str_json);
foreach (var temp in person0)
{
Console.WriteLine(temp.Age + " " + temp.Name + " " + temp.Mobiles + "\n");
}
// JObject oPostData = JsonConvert.DeserializeObject<JObject>(str_json); //@@
// oPostData.GetValue("Channel").ToString();//@@
}
}
}
Running results Here's the picture :
Hello World!
[{"Name":"China Mobile","Age":30,"Mobiles":["13800138000","10086"]},{"Name":"China Telecom","Age":60,"Mobiles":["10000","189"]},{"Name":"China Unicom","Age":90,"Mobiles":["10010"]}]
Serialization is complete , Serialized the object as a json character string
30 China Mobile System.String[]
60 China Telecom System.String[]
90 China Unicom System.String[]
D:\Users\86133\source\repos\NewTonJSONTest\NewTonJSONTest\bin\Debug\net5.0\NewTonJSONTest.exe ( process 28896) Exited , The code is 0.
To automatically close the console when debugging stops , Please enable “ Tools ”->“ Options ”->“ debugging ”->“ Automatically close the console when debugging stops ”.
Press any key to close this window . . .边栏推荐
- 【习题七】【数据库原理】
- Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
- 【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
- Differences between initial, inherit, unset, revert and all
- With pictures and texts, summarize the basic review of C language in detail, so that all kinds of knowledge points are clear at a glance?
- 剑指Offer09. 用两个栈实现队列
- Leetcode234 palindrome linked list
- [Exercice 5] [principe de la base de données]
- 双链笔记·思源笔记综合评测:优点、缺点、评价
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
猜你喜欢

GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈

4. 无线体内纳米网:电磁传播模型和传感器部署要点

记录自己vulnhub闯关记录

Public and private account sending prompt information (user microservice -- message microservice)

最新版盲盒商城thinkphp+uniapp

Analysis of a music player Login Protocol

阿里 & 蚂蚁自研 IDE

社交社区论坛APP超高颜值UI界面

Sword finger offer09 Implementing queues with two stacks

Sword finger offer05 Replace spaces
随机推荐
Analysis of the influence of voltage loop on PFC system performance
【数据库原理及应用教程(第4版|微课版)陈志泊】【第七章习题】
【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
并网-低电压穿越与孤岛并存分析
A large select drop-down box, village in Chaoyang District
Oh my Zsh + TMUX installation
[comprehensive question] [Database Principle]
【习题七】【数据库原理】
剑指Offer05. 替换空格
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
(最新版) Wifi分销多开版+安装框架
Swift Error Handling
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number
Idea packages the web project into a war package and deploys it to the server to run
Attack and defense world mobile--ph0en1x-100
【综合题】【数据库原理】
Swift return type is a function of function
Alibaba is bigger than sending SMS (user microservice - message microservice)
Ali & ant self developed IDE
十条职场规则