I read this post, but now I'm having trouble using it for my situation.
Given the following Google Maps JSON string (I am using the data structure used in Blitzmap.js
):
{
"zoom":12,
"overlays":[
{
"type": "polygon",
"paths":[
[
{ "lat":52.06630340325415, "lng":5.749811642494365 },
{ "lat":52.066277072534014, "lng":5.758523457374736 },
{ "lat":52.06306460782621, "lng":5.758544915046855 },
{ "lat":52.063011942539184, "lng":5.749811642494365 }
]
]
}
],
"center":{ "lat":52.06465767289667, "lng":5.75417827877061 }
}
When using Newtonsoft.JSON I could do:
dynamic mapObjectsAsDynamic = (JObject)formPostedData.MapObjects;
foreach (var overlay in mapObjectsAsDynamic.overlays)
{
if (overlay.type == "polygon")
{
foreach (var pathpart in overlay.paths)
{
foreach (var pathItem in pathpart.Children())
{
... = pathItem.lat;
... = pathItem.lng;
}
}
}
}
Now I like to use ServiceStack's JSON parser (ServiceStack.Text), but I am stuck on the paths
.
I tried:
var mapObjectsAsJsonObject = JsonObject.Parse(request.MapObjects);
var trial1 = mapObjectsAsJsonObject.ArrayObjects("overlays");
var trial2 = trial1[0].ArrayObjects("paths");
Is there a similar Newtonsoft way?
You can use the
.JsonTo<T>
extension method to convert yourpaths
key to aPoint[][]
then you can easily traverse the collection.Simple
Point
class:Usage (kept as similar to your usage in JSON.NET)
I hope this helps.