Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've got a Silverlight client that serializes a FeatureSet and sends to an SOE. I'd like for the SOE to deserialize the json into an IRecordSet. ESRI.ArcGIS.SOESupport.Conversion has a method for going from IRecordset to json, but not the reverse.

How can I deserialize json to create an IRecordset?

{
    "displayFieldName": "",
    "fieldAliases": {
        "OBJECTID": "OBJECTID",
        "DissolveID": "DissolveID",
        "CatchID": "CatchID",
        "Length": "Length",
        "Fnode": "Fnode",
        "Tnode": "Tnode",
        "CatchID2": "CatchID2",
        "OrigOID": "OrigOID",
        "Shape_Length": "Shape_Length"
    },
    "geometryType": "esriGeometryPolyline",
    "spatialReference": {
        "wkid": 102113
    },
    "fields": [
        {
            "name": "OBJECTID",
            "type": "esriFieldTypeOID",
            "alias": "OBJECTID"
        },
        {
            "name": "DissolveID",
            "type": "esriFieldTypeInteger",
            "alias": "DissolveID"
        },
        {
            "name": "CatchID",
            "type": "esriFieldTypeDouble",
            "alias": "CatchID"
        },
        {
            "name": "Length",
            "type": "esriFieldTypeDouble",
            "alias": "Length"
        },
        {
            "name": "Fnode",
            "type": "esriFieldTypeInteger",
            "alias": "Fnode"
        },
        {
            "name": "Tnode",
            "type": "esriFieldTypeInteger",
            "alias": "Tnode"
        },
        {
            "name": "CatchID2",
            "type": "esriFieldTypeInteger",
            "alias": "CatchID2"
        },
        {
            "name": "OrigOID",
            "type": "esriFieldTypeInteger",
            "alias": "OrigOID"
        },
        {
            "name": "Shape_Length",
            "type": "esriFieldTypeDouble",
            "alias": "Shape_Length"
        }
    ],
    "features": [
        {
            "attributes": {
                "OBJECTID": 1,
                "DissolveID": 27595,
                "CatchID": 27595,
                "Length": 2781.07146565,
                "Fnode": 26156,
                "Tnode": 26157,
                "CatchID2": 27595,
                "OrigOID": 26064,
                "Shape_Length": 3396.52480192211
            },
            "geometry": {
                "paths": [
                    [
                        [
                            -12199216.57915191,
                            4173685.6358526573
                        ],
                        [
                            -12201719.387905361,
                            4170671.685971223
                        ],
// (snip)
                        [
                            -12201768.97746418,
                            4170677.9241078123
                        ]
                    ]
                ]
            }
        }
    ]
}
share|improve this question
    
Good question! How does the generated JSON look like? –  MathiasWestin Jun 1 '11 at 5:25
    
I've added some sample json (with a lot of features snipped out). –  Kirk Kuykendall Jun 7 '11 at 17:46
    
For featureset to json Esri and json Esri to featureset you can see my post nicogis.blogspot.it/2012/04/json-arcobjects.html –  nicogis Feb 4 at 11:36
add comment

2 Answers

up vote 0 down vote accepted

You can use ESRI.ArcGIS.Geodatabase.IJSONConverterGdb

The operation handler in your SOE would have something like this:

JsonObject jsonObj;
            bool found = operationInput.TryGetJsonObject("RecordSet", out jsonObj);
            if (!found)
                throw new ArgumentNullException("RecordSet");

            string recordSetJsonString = jsonObj.ToJson();
            IJSONReader jsonReader = new JSONReaderClass();
            jsonReader.ReadFromString(recordSetJsonString);

            IJSONConverterGdb jsonConverterGdb = new JSONConverterGdbClass();

            IPropertySet originalToNewFieldMap;
            IRecordSet recordSet;
            jsonConverterGdb.ReadRecordSet(jsonReader, null, null, out recordSet, out originalToNewFieldMap);
share|improve this answer
add comment

Looks similar to what is returned when doing a query Rest Query API, when doing a plugin datasource against the REST service, we ended up deserializing the JSON query response ourself using the standard JavaScriptSerializer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.