2017-10-26 16:41:14 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2019-08-07 23:02:00 +02:00
|
|
|
|
using ln.json;
|
2019-08-08 00:34:16 +02:00
|
|
|
|
using ln.json.mapping;
|
2017-10-26 16:41:14 +02:00
|
|
|
|
|
|
|
|
|
namespace json.test
|
|
|
|
|
{
|
|
|
|
|
class MainClass
|
|
|
|
|
{
|
|
|
|
|
static string[] sources = {
|
|
|
|
|
"\"I am a string\"",
|
|
|
|
|
"{ \"me\" : \"is a string too\"}",
|
|
|
|
|
"[ \"this\", \"is\", \"an\", \"array\" ]"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
2019-08-07 23:02:00 +02:00
|
|
|
|
JSONObject json = new JSONObject()
|
|
|
|
|
.Add("version", new JSONNumber(123.456))
|
|
|
|
|
.Add("text", new JSONString("Ich bin ein Text! Lächerlich, oder?"))
|
|
|
|
|
.Add("Obst",new JSONArray()
|
|
|
|
|
.Add(new JSONString("Apfel"))
|
|
|
|
|
.Add(new JSONString("Birne"))
|
|
|
|
|
.Add(new JSONString("Zwetschge"))
|
|
|
|
|
.Add(JSONNull.Instance)
|
|
|
|
|
.Add(JSONTrue.Instance)
|
|
|
|
|
.Add(JSONFalse.Instance)
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(json.ToString());
|
|
|
|
|
|
|
|
|
|
JSONValue json2 = JSONParser.Parse(json.ToString());
|
|
|
|
|
Console.WriteLine(json2.ToString());
|
|
|
|
|
|
|
|
|
|
JSONValue value = JSONParser.Parse(File.ReadAllText("test.json"));
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("test.json file:");
|
|
|
|
|
Console.WriteLine("PARSED: {0}",value.ToString());
|
2019-08-08 00:34:16 +02:00
|
|
|
|
|
|
|
|
|
Person person = new Person()
|
|
|
|
|
{
|
|
|
|
|
firstname = "Harald",
|
|
|
|
|
lastname = "Wolff-Thobaben",
|
|
|
|
|
age = 39
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
JSONValue jsonPerson = JSONMapper.DefaultMapper.ToJson(person);
|
|
|
|
|
Console.WriteLine(jsonPerson.ToString());
|
|
|
|
|
|
|
|
|
|
Person p2 = JSONMapper.DefaultMapper.FromJson<Person>(jsonPerson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Person
|
|
|
|
|
{
|
|
|
|
|
public string firstname;
|
|
|
|
|
public string lastname;
|
|
|
|
|
|
|
|
|
|
public int age;
|
2019-08-07 23:02:00 +02:00
|
|
|
|
}
|
2019-08-08 00:34:16 +02:00
|
|
|
|
}
|
2017-10-26 16:41:14 +02:00
|
|
|
|
}
|