Wednesday, 8 February 2017

arcobjects - How can I deserialize json to create an IRecordset?


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

}
}
]
}

Answer



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);

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...