- Updated examples

This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-28 16:52:32 +02:00
parent ea53555923
commit 116b7bd4a9
2 changed files with 24 additions and 4 deletions

View File

@ -15,6 +15,7 @@ struct Person
public float[] list3; public float[] list3;
public double[] list4; public double[] list4;
public string[] list5; public string[] list5;
public EnumType animal;
} }
``` ```
@ -31,7 +32,8 @@ Now, let's say we were given the following JSON:
"list2": [true, false], "list2": [true, false],
"list3": [1.5, 1.4], "list3": [1.5, 1.4],
"list4": [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], "list2": [true, false],
"list3": [1.5, 1.4], "list3": [1.5, 1.4],
"list4": [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: 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)
``` ```

View File

@ -10,6 +10,17 @@ struct Person
public int age; public int age;
public string[] list; public string[] list;
public JSONValue extraJSON; 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.age = 23;
p1.list = ["1", "2", "3"]; p1.list = ["1", "2", "3"];
p1.extraJSON = parseJSON(`{"item":1, "items":[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: Now, we make a call to `serializeRecord` as follows:
@ -35,6 +47,7 @@ This returns the following JSON:
```json ```json
{ {
"age": 23, "age": 23,
"eType": "CAT",
"extraJSON": { "extraJSON": {
"item": 1, "item": 1,
"items": [ "items": [
@ -45,6 +58,10 @@ This returns the following JSON:
}, },
"firstname": "Tristan", "firstname": "Tristan",
"lastname": "Kildaire", "lastname": "Kildaire",
"list": ["1", "2", "3"] "list": [
"1",
"2",
"3"
]
} }
``` ```