Create Geometry from JSON string

3004
3
Jump to solution
07-18-2012 05:17 AM
MichaelOberegger
New Contributor
Hi everyone!

The Flex API's Geometry class has a static method called fromJSON() that lets you easily get a Geometry object from a JSON string that respresents a geometry. For example, you could do something like Geometry.fromJSON("\"geometry\":{\"x\":-10619660.612597,\"y\":3474324.60413219") and receive a Point object.

Does the Silverlight API have something similar to this? I see that the FeatureSet and FeatureLayer classes have a FromJson method, but they require more than a more complex JSON string that contains more than just the geometry values, and will also create an entire FeatureSet or FeatureLayer that I don't need.

How would I go about doing something like this? Any help would be greatly appreciated!

Thanks!

Mike
0 Kudos
1 Solution

Accepted Solutions
DaveTimmins
Occasional Contributor II
Hi,

there is an internal API class called ArcGISJsonReader which does this but since it's internal you can't use it. If you use something like Telerik JustDecompile you can inspect the code and make your own though.

Cheers,

View solution in original post

0 Kudos
3 Replies
DaveTimmins
Occasional Contributor II
Hi,

there is an internal API class called ArcGISJsonReader which does this but since it's internal you can't use it. If you use something like Telerik JustDecompile you can inspect the code and make your own though.

Cheers,
0 Kudos
MichaelOberegger
New Contributor
Not the answer I was hoping for, but thank you for the reply!

Out of curiosity, is there a particular reason that this feature in not implemented in the Silverlight version (since the feature exists in Flex)? Is this something that will/could be implemented in a future version of the Silverlight API?

Thanks again!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
As FromJson does exist for a Featureset, the workaround may be to create a FeatureSet with only one geometry and return that geometry.

Something like:
static Geometry FromJson(string json)
{
    return FeatureSet.FromJson(@"{""features"":[{" + json + @"}]}").Features.First().Geometry;
}
0 Kudos