1
votes

I'm making a simple web call (GET) to an api that returns some json. Trouble is, I can't parse it with Newtonsoft (or otherwise) because the HTTP Utility RequestString response.Body is prepended with the word "Text".

Text
  "[{"name":"10 Years","desc":"","descData":null,"closed":false  ...

What can I do to avoid this and get my json string as an actual json string?

1
That doesn't look like it's "prepended", it looks like it's wrapped in a constructor. How did you determine that it's "prepended" exactly? - Fyodor Soikin
Sorry. That was just a lack of understanding and the only way I knew how to describe it. - fischgeek

1 Answers

2
votes

If you take a look at the FSharp.Data Http Utils ResponseBody docs you will notice it returns a Discriminated Union with 2 options.

So you will want to handle it with something like this:

let myHttphandler resp =
    match resp with
    | Text txt -> txt |> customTextHandler
    | Binary bytes -> bytes |> customBytesHandler

Of course, if you know you will always get text, use _ in your DU.

Your customTextHandler function will probably deserialize your json.