0

Hi i am very new to xamarin development, i want to parse a simple Json response and display the message which is coming from the server. The Json format is given below.

{"email": {"message": "Email already Verified"}}

any help?

2
  • 1
    Possible duplicate of Deserialize JSON with C# Commented Dec 5, 2018 at 7:37
  • check out Json.net. You've shown no code about how you get the data so there not much else we can suggest Commented Dec 5, 2018 at 7:39

2 Answers 2

1

There is an awesome service QuickType.io where you can just copy your JSON, select the target language and get a working example of deserialisation.

Here is the output generated for the JSON you shared above:

// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var welcome = Welcome.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class Welcome
    {
        [JsonProperty("email")]
        public Email Email { get; set; }
    }

    public partial class Email
    {
        [JsonProperty("message")]
        public string Message { get; set; }
    }

    public partial class Welcome
    {
        public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this Welcome self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
    }

    internal static class Converter
    {
        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
        {
            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
            DateParseHandling = DateParseHandling.None,
            Converters =
            {
                new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
            },
        };
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks to all for the help provided, after some research i have created a class to save the values of the JSON and solved the issues,

the solution i am adding below

public class Email
{
    public string message { get; set; }
}

public class Success
{
    public Email email { get; set; }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.