0

[ASK] C# Xamarin JSOn

String a = "{\"success\":1,\"message\":\"successfully created.\"}";
string b = "{"success":1,"message":"successfully created."}";

how to get value success and message in JSON ?

tequila slammer
  • 2,821
  • 1
  • 18
  • 25
Soma Kun
  • 41
  • 3
  • Please clarify your question. What is the relationship between `a` and `b` in the above? If your question is asking how to convert an object into JSON, JsonConvert.SerializeObject looks promising. http://stackoverflow.com/questions/16294963/json-net-serialize-object-with-root-name or http://stackoverflow.com/questions/15843446/c-sharp-to-json-serialization-using-json-net – Seth Difley Oct 22 '16 at 02:48

1 Answers1

1

Given the class model of (via http://jsonutils.com):

public class Example
{
    public int success { get; set; }
    public string message { get; set; }
}

Usage:

var a = "{\"success\":1,\"message\":\"successfully created.\"}";
var example = JsonConvert.DeserializeObject<Example>(a);
Console.WriteLine($"{example.success} : {example.message}");

Output:

1 : successfully created.
SushiHangover
  • 73,120
  • 10
  • 106
  • 165