Soma Kun
Soma Kun

Reputation: 41

How to make string to JSON using JSON.NET

[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 ?

Upvotes: 0

Views: 714

Answers (1)

SushiHangover
SushiHangover

Reputation: 74124

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.

Upvotes: 1

Related Questions