There is a json in which the points are stored, from which, in consequence, certain 3d objects are built, in fact, the coordinates of the vertices. The peculiarity is that they lie at uneven depth.
As can be seen in the 31st "set" of points, they lie immediately after the "coordinates" node and in the 32nd after this node they are further divided into 2 groups, and within the group there is the desired set of points. The task is to go through the nodes to the elements constituting the sets of points (the green elements are the coordinates of xy itself), collect the points belonging to one set in the list, send them for processing and continue moving along json. The difficulty is that where they are divided into groups (32nd), each group of elements must be sent separately, as if it were finished (as in the case of the 31st, we walked 0,1,2 collected points inside sent let's go further), that is, go 32-geometry-> coordinates-> 0 to collect everything inside and send then to 32-geometry-> coordinate-> 1 to send, then just further. It would be logical to assume that there where type: MultiLineString you can simply add another cycle of passing through the elements, but something tells me that I am wrong. How to solve this problem correctly in terms of practicing parsing json files?
Sorry for the messy description, tried to detail as I could.
update in this way I tried to get to the data I needed, but the data from the 32nd group merged into one list and I never figured out how to RIGHT, I get them. Now I understand judging by the comments and answers that I got close to the task from the fundamentally wrong side.
private void CreateRoads(JSONObject mapData) { int count = 0; foreach (var geo in mapData["features"].list) { count++; var l = new List<Vector3>(); for (int i = 0; i < geo["geometry"]["coordinates"].list.Count; i++) { if (!geo["geometry"]["coordinates"][i][0].IsNumber) { for (int j = 0; j < geo["geometry"]["coordinates"][i].list.Count; j++) { var c = geo["geometry"]["coordinates"][i][j]; var bm = GM.LatLonToMeters(c[1].f, c[0].f); var pm = new Vector2(bm.x - Rect.center.x, bm.y - Rect.center.y); l.Add(pm.ToVector3xz()); } } else { var c = geo["geometry"]["coordinates"][i]; var bm = GM.LatLonToMeters(c[1].f, c[0].f); var pm = new Vector2(bm.x - Rect.center.x, bm.y - Rect.center.y); l.Add(pm.ToVector3xz()); } } var m = new GameObject("road_" + count.ToString()).AddComponent<RoadPolygon>(); m.transform.localPosition = new Vector3(m.transform.localPosition.x, m.transform.localPosition.y + 1f, m.transform.localPosition.z); m.transform.parent = this.transform; try { m.Initialize(geo["properties"]["id"].str, this, l, geo["properties"]["kind"].str); } catch (Exception ex) { Debug.Log(ex); } } }
I managed with deserialization, thanks @ sp7, but I don’t understand how to arrange different levels of depth for the blocks. What would it be universal, and not hardcode. There are thoughts on the topic of the passage to the depth of the last node (it differs in the fact that it has children), from it up to the level, collect the desired data (lists with coordinates), send, go up a level, see if there are any lists, no up again if you went to the coordinates block, then go to the next number (33,34,35) and so on ... the only problem is that I don’t know how to make such a depth passage. And googling did not help much = /
var root = JsonConvert.DeserializeObject<Rootobject>(www.text); var features = root.roads.features; List<object[][]> coordinates = new List<object[][]>(); for (int i = 0; i < features.Length; i++) { coordinates.Add(features[i].geometry.coordinates); } ConstructRoad(coordinates);