forked from IoTSharp/IoTSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonConverTest.cs
34 lines (30 loc) · 1009 Bytes
/
JsonConverTest.cs
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
using IoTSharp.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using IoTSharp.Data;
namespace IoTSharp.Test
{
[TestClass]
public class JsonConverTest
{
[TestMethod]
public void TestJsonObject()
{
var jojb = JToken.Parse("{\"aaa\":\"bbb\"}");
Dictionary<string, object> keyValues = new Dictionary<string, object>();
jojb.Children().ToList().ForEach(a => keyValues.Add(((JProperty)a).Name, ((JProperty)a).JPropertyToObject()));
Assert.AreEqual<string>("bbb", keyValues["aaa"].ToString());
}
[TestMethod]
public void TestDic()
{
var sss = new Dictionary<string, object>();
sss.Add("eee", "fff");
sss.Add("ggg", "hhh");
sss.Add("iii", "kkk");
Assert.IsNotNull(Newtonsoft.Json.JsonConvert.SerializeObject(sss));
}
}
}