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.

The value part of a GP Result can be any type of GP object (or literal).

Does anyone know of a general way to deserialize this, preferably with either WCF or Json.NET?

I'd prefer not to have to write a deserializer for each different GP tool.

{
   "results":[
      {
         "paramName":"Output",
         "dataType":"GPFeatureRecordSetLayer",
         "value":{
            "geometryType":"esriGeometryPolyline",
            "spatialReference":{
               "wkid":4326
            },
            "features":[
               {
                  "geometry":{
                     "paths":[
                        [
                           [
                              -91.6849975582907,
                              24.206096649241
                           ],
                           [
                              -91.8398132323948,
                              24.4056720735074
                           ]
                        ]
                     ]
                  },
                  "attributes":{
                     "FID":1,
                     "FNODE_":0,
                     "Shape_Length":0.25258314060805
                  }
               }
            ],
            "exceededTransferLimit":"false"
         }
      }
   ],
   "messages":[

   ]
}  

Update: I never figured out a way to do this. If Esri wants to encourage consumption of GP services by a wider variety of clients they should consider serializing the .NET type name, similar to what can be done with Json.NET by setting TypeNameHandling = Objects.

share|improve this question
    
Any progress I'm having similar problems with the result from a query. Should we add an Idea on ESRIs website that we can vote up? –  MathiasWestin Feb 16 '11 at 14:47
    
Any idea if u guys were able to solve it? I am also getting the same and my output result contains 3076 features. Any suggestions how to resolve it? –  Sam007 Nov 27 '12 at 2:14
add comment

2 Answers

Json.NET supports deserializing into anonymous types, but it's not as helpful as I'd originally thought - you have to provide a template:

var example = new { paramName = string.Empty, dataType = string.Empty };
var gpResult = JsonConvert.DeserializeAnonymousType(json, example);

It would get you part of the way to what you're looking for, but you'd still have to do some work afterwards to move the data into more statically typed data structures. You could at least have better visibility into the datatypes and switch (or subclass) as needed from there.

Unfortunately, given the variability of the content in the responses, I don't see how you could make a class that would be able to represent it properly / generically.

Update:

If you're using C# 4, apparently Json.NET supports the dynamic data type. That might be of more help. I'm not using it here, so I can't test and see what'd happen, unfortunately. There may be some information of value over this way.

share|improve this answer
add comment

See my answer to your other question, it might provide some context and help.

share|improve this answer
    
You mean this one? gis.stackexchange.com/questions/2411/… –  Herb Oct 7 '10 at 13:07
    
@Herb: thanks, link corrected –  Petr Krebs Oct 7 '10 at 13:21
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.