Так что мне нужно разобрать строку JSON из моего проекта C#. Я получаю JSON в качестве ответа от вызова метода и JSON выглядит следующим образом:C# доступ к содержимому JSON по ID
{
"10": {
"entity_id": "10",
"attribute_set_id": "4",
"type_id": "simple",
"sku": "convertor-touchscreen",
"name": "Convertor touchscreen",
"meta_title": null,
"meta_description": null,
"url_key": "convertor-touchscreen",
"custom_design": null,
"page_layout": null,
"options_container": "container1",
"country_of_manufacture": null,
"msrp_enabled": "2",
"msrp_display_actual_price_type": "4",
"gift_message_available": null,
"creareseo_discontinued": null,
"creareseo_discontinued_product": null,
"description": "Convertor touchscreen",
"short_description": "Convertor touchscreen",
"meta_keyword": null,
"custom_layout_update": null,
"price": "421.0000",
"special_price": "380.0000",
"weight": "0.1500",
"msrp": null,
"special_from_date": "2015-11-24 00:00:00",
"special_to_date": "2015-11-26 00:00:00",
"news_from_date": null,
"news_to_date": null,
"custom_design_from": null,
"custom_design_to": null,
"status": "1",
"visibility": "4",
"tax_class_id": "2",
"featured": "1"
}
}
Поэтому мне нужно, чтобы получить доступ пользователей как «ENTITY_ID», «имя» и так далее ... поэтому я попытался
using Newtonsoft.Json.Linq;
...
// output is the above JSON string
var jo = JObject.Parse(output);
var id = jo[0]["entity_id"].ToString();
Но, очевидно, это нехороший способ сделать это. Кроме того, у меня нет контроля над первой частью
{
"10": {
Так что я не могу сделать
var id = jo["10"]["entity_id"].ToString();
, потому что я не знаю, что значение «10» будет в моей следующей строке JSON. Итак, как я могу получить значение элемента с помощью идентификатора или чего-то еще?
Непонятно, что вы * делаете * знаете. Будет ли когда-нибудь единое целое в JSON? Как вы думаете, «не очень хорошо» о том, что у вас есть? –