Convert string to JSON in C #

I am trying to use Simple JSON to convert this string to JSON:

"{\"objects\":[{\"id\":1,\"title\":\"Book\",\"position_x\":0,\"position_y\":0,\"position_z\":0,\"rotation_x\":0,\"rotation_y\":0,\"rotation_z\":0,\"created\":\"2016-09-21T14:22:22.817Z\"},{\"id\":2,\"title\":\"Apple\",\"position_x\":0,\"position_y\":0,\"position_z\":0,\"rotation_x\":0,\"rotation_y\":0,\"rotation_z\":0,\"created\":\"2016-09-21T14:22:52.368Z\"}]}"

Unfortunately, it seems that Visual Studio does not have an interactive debugging console. As in the case of placing the debugger in a line and entering this part of the code in the interactive console. Where could I be able to experiment with the SimpleJSON library and see how to do it. By all means, correct me if I am wrong!

If this were not possible, would anyone know how to do this? I tried this:

JSONData jsonData = new JSONData(my_json_string);

But this eludes the string and saves it as a string:

"\"{\\\"objects\\\":[{\\\"id\\\":1,\\\"title\\\":\\\"Book\\\",\\\"position_x\\\":0,\\\"position_y\\\":0,\\\"position_z\\\":0,\\\"rotation_x\\\":0,\\\"rotation_y\\\":0,\\\"rotation_z\\\":0,\\\"created\\\":\\\"2016-09-21T14:22:22.817Z\\\...

I am new to C #, but I am surprised that there is nothing native to C # that would do something in common, like JSON parsing more accessible. There is one?

+4
2

. json2sharp, .

public class Item
{
    public int id { get; set; }
    public string title { get; set; }
    public int position_x { get; set; }
    public int position_y { get; set; }
    public int position_z { get; set; }
    public int rotation_x { get; set; }
    public int rotation_y { get; set; }
    public int rotation_z { get; set; }
    public string created { get; set; }
}

Newtonsoft.Json .

var list = JsonConvert.DeserializeObject<List<Item>>(Yourjson);
+9

?

https://msdn.microsoft.com/ru-ru/library/system.json.jsonvalue.parse%28v=vs.95%29.aspx

public static JsonValue Parse(string jsonString)

JsonValue, jsonobject .

0

Source: https://habr.com/ru/post/1655956/


All Articles