Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Using JsonConvert.DeserializeObject

Can anyone help me just deserialize a simple JSON response, I can't seem to find the answer anywere!
JSON Response: "{\"AuthResponse\":true,\"ContactID\":9999}"

I just want to be able to store the single line response to local variables.

var response = await httpClient.GetStringAsync(myURL);

//response returns "{\"AuthResponse\":true,\"ContactID\":9999}"

var bool AuthRespsone = "This is the part I need help with"

Best Answer


  • KevinMcCarthyKevinMcCarthy USMember ✭✭
    edited January 24

    @LandLu I did implement those changes and now I am getting:

    Newtonsoft.Json.JsonSerializationException: 'Error converting value "{"AuthResponse":true,"ContactID":9999}" to type 'USM.Model'. Path ''

    Yet if I hard code the string as in your example, it deserializes it fine! It's like Xamarin doesn't like my JSON!

    Thanks in advanced!

  • LandLuLandLu Member, Xamarin Team Xamurai

    Try to check the validation of your json string here:
    It seems the string is invalidated lacking symbols like "\".

  • KevinMcCarthyKevinMcCarthy USMember ✭✭

    It did return Valid when copying the response from Postman. I must be missing something.

  • KevinMcCarthyKevinMcCarthy USMember ✭✭
    edited January 25

    Thanks for the snippet, my issue dealt with casting the API back to mobile app. Postman was able to handle it, Xamarin was not. So I made some changes on the API level and your code worked great!


Sign In or Register to comment.