Skip to main content

Workflow WebRequest response conversion

Comments

6 comments

  • Ryan Cooney
    Hi Ibrahim,

     

    The text you are trying to parse is a JSON array so you'll want to do something like this in an Assign activity: Newtonsoft.Json.Linq.JArray.Parse(MunicipalitiesAsString) This returns an Object, but you can then Cast it to a Newtonsoft.Json.Linq.JArray. The JArray object can be enumerated. http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JArray.htm

     

    There are lots of ways to parse JSON data, but the Netwonsoft library is a great choice.

     

    --Ryan
    0
  • Ryan Cooney
    Minor correction. JArray.Parse(string) does return a JArray so there is no need for the extra cast. http://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Linq_JArray_Parse.htm

     

    --Ryan
    0
  • Permanently deleted user
    Hi Ryan,

     

    Thank you for the directions ;)

     

    I was not aware of the Newtonsoft library, it seems like it fulfills more than the Jayrock library.

     

    Kind regards,

     

    Ibrahim
    0
  • Bryan Lynn
    @Ryan, I am trying to do basically the same thing - read a string of JSON objects but I keep getting the following error when I run the workflow:

     

    Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself

     

    Any suggestions?

     

    Thanks,

     

    Bryan
    0
  • Permanently deleted user
    @Bryan, were you able to resolve this.  I'm running into the same trouble.

     

     

    Dave
    0
  • Bryan Lynn
    @David Flack, I did figure it out but I can't remember exactly what the issue was because I can't remember which workflow I was working on at the time. Here is the last one I remember having issues with. I got around it by using the JsonToDictionary task then casting it to an array of objects and iterating over the array casting to individual objects. I have attached the workflow so you can see how I did it. It also includes a sample JSON file that you will need to copy to your server and update the DownloadString task to point at the file. Hope that helps....
    0

Please sign in to leave a comment.