Flatten
public LitJson.JsonData Flatten(LitJson.JsonData jsonData);
Parameter
Value | Type | Description |
---|---|---|
jsonData | Litjson.JsonData | BackendReturnObject's Rows() or GetReturnValuetoJSON() containing data received from the server |
Description
This is a way to delete the data type included in the return value of GetReturnValuetoJSON() and Rows() methods and extract only the stored data.
- The data stored through data unmarshalling can be converted for convenient use.
- The pieces of data stored as strings among the numeric type can be converted to long or double depending on each data type.
- Unmarshalled data can be deserialized to a class. Please refer to the Deserialize documentation.
- When flattening, the entirety of the JsonData, which is the parameter value of the method, is traversed.
Normally there is no issue related to speed, but if the data is complex or large, performance issues may occur.
It takes about 11 ms to flatten the rows() that include 100 pieces of data equivalent to the following ReturnValue.
Example
var bro = Backend.GameData.Get("inventory", new Where(), 100);
if(bro.IsSuccess() == false)
{
return;
}
// data1 and data2 are the same result.
var data1 = BackendReturnObject.Flatten(bro.Rows());
var item1 = data1[0];
var data2 = bro.FlattenRows();
var item2 = data2[0];
// data3 and data4 are the same result.
var data3 = BackendReturnObject.Flatten(bro.GetReturnValuetoJSON());
var item3 = data3["rows"][0];
var data4 = bro.GetFlattenJSON();
var item4 = data4["rows"][0];
// item1 - item4 are eventually all the same value.
ReturnValue
Return value after unmarshalling(all data types are deleted)
{
{
"client_date": "2020-11-02T08:11:04.609Z",
"nickname": "Applemango",
"def": 75,
"inDate": "2020-11-02T08:11:04.79Z",
"atk": 63,
"option": {
"opt1": "empty",
"opt2": "empty"
},
"updatedAt": "2020-11-02T08:11:04.786Z",
"socket": [
115,
174,
257
],
"name": "name39",
"critical": 2.71338716834476
}
}
Return value before unmarshalling(data types are included)
{
{
"client_date": {
"S": "2020-11-02T08:11:05.631Z"
},
"nickname": {
"S": "Applemango"
},
"def": {
"N": "42"
},
"inDate": {
"S": "2020-11-02T08:11:05.828Z"
},
"atk": {
"N": "55"
},
"option": {
"M": {
"opt1": {
"S": "empty"
},
"opt2": {
"S": "empty"
}
}
},
"updatedAt": {
"S": "2020-11-02T08:11:05.826Z"
},
"socket": {
"L": [
{
"N": "115"
},
{
"N": "170"
},
{
"N": "255"
}
]
},
"name": {
"S": "name47"
},
"critical": {
"N": "2.81677461593262"
}
}
}