From JSON to MapPoint
In my workflow, I've got a string variable holding a string which represents a MapPoint in JSON format. For instance, when I simulate the workflow, the string looks like this:
{ "x" : 1945761.21727366, "y" : 715756.433240193, "spatialReference" : { "wkid" : 32043 } }
But how I get that into an ESRI.ArcGIS.Client.Geometry.MapPoint is beyond me--I've been trying for hours now. Can someone with more knowledge of .NET, Workflow Designer, and JSON lend me a hand on this? I'd sure appreciate it.
-
Roger,
I've never tried assigning a mappoint to a parsed value so I looked over some of the workflows that I have that get the mappoint from user input and thought perhaps the following will work:
create a variable:
esriPoint esri.arcgis.client.geometry.MapPoint
jsonX double
jsonY double
jsonSpatialExtent Int32parse out spatialreference, x, and y from the json string
assign
esriPoint.X = jsonX
esriPoint.Y = jsonY
esriPoint.spatialreference = new esri.ArcGIS.Client.Geometry.SpatialReference(jsonSpatialExtent)0 -
Hi Roger,
Out of curiosity, where did you get the Json from? Is it just hard coded, or did you get it from some interaction with the client? If you properly type variables as Geomety in the workflow, they would be created correctly coming from the client.
We have some internal methods that we use in the product to get geometry from Json. I'll put in a feature request to expose it as public in the future (won't help you right now).
Cheers,
Christian.
0 -
I knew someone would ask. I have my own geocoding service that's specific to the city I work for. It used to be SOAP based, but I added a REST endpoint last week. But now that I can get a JSON response from geocoding in the URL, I don't know what to do with it. I've tried casting the string to a MapPoint or a Geometry and many other things. I thought it would be simple, but I guess it's not.
As far as the parsing goes, I was hoping I could find a class that would do it for me (you know, stripping out the quotes, breaking on commas, etc.) I did see a class called JsonReaderWriterFactory, but don't know how to use it. I just need something to break that JSON value into pairs, and then read the X and Y. Then I'd feel comfortable giving those to a new MapPoint.
0 -
Try this:
Geometry geo = new MapPoint //Assign
MapPoint pt = geo.FromJson(strJson) //Cast to point0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
4 kommentarer