Parsing Error

Jan 6, 2013 at 10:21 PM

I am trying to parse this simple response to retreive the name field.

  "success": [
      "id": 2,
      "name": "Terminal  Base Software",
      "canEdit": true,
      "sprintSupportEnabled": false

I have the folloiwng simple function


protected bool TryGetPath(out JToken token, params object [] paths) {

    token = JObject; 

    foreach (object path in paths)


         if (token == null) return false ;

         token = token[path];


     return token != null ;


I call token[path] where path is first "success" then "name" and the call with name as the key fails with an error

Additional information: Accessed JArray values with invalid key value: "name". Array position index expected. 

What am I doing wrong?


Jan 7, 2013 at 12:19 AM
Edited Jan 7, 2013 at 12:20 AM

Success contains an array of child objects.  The first ( and only ) element ( index zero ) contains the object literal with the name element you are after.

success:[{...}]  - notice the square brackets.