0

all what i want to make class that have properties slimier to this json.

{"code":200,"detected":{"lang":"en"},"lang":"en-ar","text":["hello"]} 

i tried many times please help

3 Answers 3

3

If you're using Visual Studio 2013 Update 2 and above, you'll find that it can generate this JSON-compatible class for you.

Just copy a sample JSON structure (like the one you posted here), go to any .cs file, and go to Edit -> Paste Special -> Paste JSON as Classes. VS will automatically generate a class for you that your JSON can be deserialized into.

Sign up to request clarification or add additional context in comments.

Comments

2

The following model should work:

public class MyModel
{
    public int Code { get; set; }
    public Detected Detected { get; set; }
    public string Lang { get; set; }
    public string[] Text { get; set; }
}

public class Detected
{
    public string Lang { get; set; }
}

and then you can deserialize to it:

string json = ...
var model = JsonConvert.DeserializeObject<MyModel>(json);

Comments

1

I find json2csharp very helpful in converting json samples to C# classes/pocos which I then use with Json.NET.

2 Comments

This is not an answer. This kind of thing belongs on your blog
This is one of the solutions hence an answer to the problem. Certainly nothing to write a blog post about :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.