3

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
                        ]
                    ]
                ]
            }
        }
    ]
}
3

2 Answers 2

1

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);
1
  • Not specifically asked for but also common to go to IFeatureClass: IFeatureClass featClass = (IFeatureClass)recordSet.Table
    – Josh Werts
    Jan 8, 2015 at 20:20
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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