Hi there.
I’ve been reading everything I found about raw JSON deserializing to objects, but I’m to newbee to face this JSON structure:
I understand how to load my Items to an array of ClimatPoly[ ] type, but I don’t know how to deserialize the contained Points array…
Here is a sample of the JSON file :
{
"Items": [
{
"Coordonnees": "iOS",
"id": "P1_CL_GC_3",
"Points": ["{0.8153064005433652, 0.22303484578714347}", "{0.8153647996297442, 0.22523130031371963}", "{0.8149728519153944, 0.22687271395095307}"]
},
{
"Coordonnees": "iOS",
"id": "P1_CL_GC_4",
"Points": ["{0.8217868273658131, 0.23282567723040115}", "{0.8233755819978078, 0.23300087448953702}"]
}
]
}
Here is my object class structure :
Basically, I want to fill “lesClimatsPoly” array with the items from the JSON file, but I also need to fill the variable length array “Points” inside the ClimatPoly class.
public static class ClimatPolyArray
{
public struct Point
{
public float x, y;
public Point(float px, float py)
{
x = px;
y = py;
}
}
public class ClimatPoly
{
public string Coordonnees;
public string id;
public Point[] Points;
}
public static ClimatPoly[] lesClimatsPoly;
//public string Nom;
public static void Load()
{
string theFile = "jsontestfile.json";
string filepath = Path.Combine(Environment.CurrentDirectory, @"Assets\Resources\", theFile);
string jsonString = File.ReadAllText(filepath);
Debug.Log("jsonString : " + jsonString);
[...]
}
I’ve been looking at the chapter called “2. MULTIPLE DATA(ARRAY JSON)” on stackoverflow, but I dont know where to go from here…
Any help would be greatly appreciated.