-
Notifications
You must be signed in to change notification settings - Fork 252
/
Json.txt
30 lines (25 loc) · 801 Bytes
/
Json.txt
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
// use json.net
https://components.xamarin.com/view/json.net/
using Newtonsoft.Json;
...
public class Person
{
public string Name { get; set; }
public DateTime Birthday { get; set; }
}
void PersonToJsonToPersonExample ()
{
var person = new Person { Name = "Bob", Birthday = new DateTime (1987, 2, 2) };
var json = JsonConvert.SerializeObject (person);
Console.WriteLine ("JSON representation of person: {0}", json);
var person2 = JsonConvert.DeserializeObject<Person> (json);
Console.WriteLine ("{0} - {1}", person2.Name, person2.Birthday);
}
using Newtonsoft.Json.Linq;
...
void LinqExample ()
{
string json = @"{ Name: 'Bob', HairColor: 'Brown' }";
var bob = JObject.Parse (json);
Console.WriteLine ("{0} with {1} hair", bob["Name"], bob["HairColor"]);
}