mirror of https://github.com/Hax-io/jstruct
- Updated examples
This commit is contained in:
parent
ea53555923
commit
116b7bd4a9
|
@ -15,6 +15,7 @@ struct Person
|
|||
public float[] list3;
|
||||
public double[] list4;
|
||||
public string[] list5;
|
||||
public EnumType animal;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -31,7 +32,8 @@ Now, let's say we were given the following JSON:
|
|||
"list2": [true, false],
|
||||
"list3": [1.5, 1.4],
|
||||
"list4": [1.5, 1.4],
|
||||
"list5": ["baba", "booey"]
|
||||
"list5": ["baba", "booey"],
|
||||
"animal": "CAT"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -49,7 +51,8 @@ JSONValue json = parseJSON(`{
|
|||
"list2": [true, false],
|
||||
"list3": [1.5, 1.4],
|
||||
"list4": [1.5, 1.4],
|
||||
"list5": ["baba", "booey"]
|
||||
"list5": ["baba", "booey"],
|
||||
"animal": "CAT"
|
||||
}
|
||||
`);
|
||||
|
||||
|
@ -66,5 +69,5 @@ writeln(person):
|
|||
Which will output:
|
||||
|
||||
```
|
||||
Person("Tristan", "Kildaire", 23, true, {"bruh":1}, [1, 2, 3], [true, false], [1.5, 1.4], [1.5, 1.4], ["baba", "booey"])
|
||||
Person("Tristan", "Kildaire", 23, true, {"bruh":1}, [1, 2, 3], [true, false], [1.5, 1.4], [1.5, 1.4], ["baba", "booey"], CAT)
|
||||
```
|
|
@ -10,6 +10,17 @@ struct Person
|
|||
public int age;
|
||||
public string[] list;
|
||||
public JSONValue extraJSON;
|
||||
public EnumType eType;
|
||||
}
|
||||
```
|
||||
|
||||
Our enum is defined as:
|
||||
|
||||
```d
|
||||
enum EnumType
|
||||
{
|
||||
DOG,
|
||||
CAT
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -22,6 +33,7 @@ p1.lastname = "Kildaire";
|
|||
p1.age = 23;
|
||||
p1.list = ["1", "2", "3"];
|
||||
p1.extraJSON = parseJSON(`{"item":1, "items":[1,2,3]}`);
|
||||
p1.eType = EnumType.CAT;
|
||||
```
|
||||
|
||||
Now, we make a call to `serializeRecord` as follows:
|
||||
|
@ -35,6 +47,7 @@ This returns the following JSON:
|
|||
```json
|
||||
{
|
||||
"age": 23,
|
||||
"eType": "CAT",
|
||||
"extraJSON": {
|
||||
"item": 1,
|
||||
"items": [
|
||||
|
@ -45,6 +58,10 @@ This returns the following JSON:
|
|||
},
|
||||
"firstname": "Tristan",
|
||||
"lastname": "Kildaire",
|
||||
"list": ["1", "2", "3"]
|
||||
"list": [
|
||||
"1",
|
||||
"2",
|
||||
"3"
|
||||
]
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue