Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In one of the Net API controllers, I have an action which sends the request to another third party API and after receiving a response it does some manipulation with the JSON data received and finally returns the response to the frontend application. Sample code is given below:

using (var client = new HttpClient())
    var response = await client.GetAsync(_remoteServiceEndPoint + "student/" + id);
    if (response.IsSuccessStatusCode)
        var contentString = await response.Content.ReadAsStringAsync();
        //do something with contents and finally return response to the caller

Now if the third party sends a JSON response which contains a number like 999999999999999.99 and the ReadAsStringAsync executes in the above code snippet, it changes the value to 10000000000000000. Which I don't want.

I would like to know why ReadAsStringAsync is behaving like this.

Are you sure the call to ReadAsStringAsync() is causing the problem? I'd suspect that to work fine, but you'd get a problem when deserializing the string with NewtonSoft. – Jesse de Wit Apr 26, 2019 at 12:04 This sounds like a bug that should be reported in the corefx repo, but I agree with Jesse - I can't see any reason why ReadAsStringAsync would ever need or want to modify the data it's retrieving. – Ian Kemp Apr 26, 2019 at 12:13 @AJQarshi Great, I was sweating a bit for all the calls to ReadAsStringAsync I'd written in the past. – Jesse de Wit Apr 26, 2019 at 12:48

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.