https://blog.csdn.net/dslobo/article/details/108815969
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
{
"accepttime": 1600966807,
"certificate": "",
"completetext": "",
"completetime": 1601010419,
"createtime": 1600966807,
"deleteflag": 0,
"endtimestr": "12:00",
"gid": 42,
"netbarCameraList": [{
"account": "admin",
"address": "172.16.36.17",
"cameraid": 21,
"gid": 42,
"name": "36",
"password": "52358",
"port": 554
}],
"netbarname": "36新亚网吧",
"uniacid": 6,
"userid": 66
}
|
1
2
|
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// 读取外部json格式文件
string text = File.ReadAllText(@"C:\Users\Administrator\Desktop\111.txt");
byte[] mybyte = Encoding.UTF8.GetBytes(text);
string aaa = Encoding.UTF8.GetString(mybyte);
//Console.WriteLine(aaa); aaa为字符串类型
//将JSON反序列化为.NET对象。
JObject jo1 = (JObject)JsonConvert.DeserializeObject(aaa);
//第一层
string name = jo1["netbarname"].ToString();
Console.WriteLine(name);
string netbarCameraList = jo1["netbarCameraList"].ToString();
Console.WriteLine(netbarCameraList);
//第二层
string account = jo1["netbarCameraList"][0]["account"].ToString();
Console.WriteLine(account);
string address = jo1["netbarCameraList"][0]["address"].ToString();
Console.WriteLine(address);
}
}
}
|