所以我需要从我的C#项目解析JSON字符串。 让我的JSON从一个方法调用的响应和JSON看起来是这样的:C#通过ID访问JSON内容
{
"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字符串的内容。 那么如何通过Id或其他东西获取元素值?
你不知道你*知道什么。在JSON中只会有一个实体吗?你认为什么是对你所拥有的东西“不是一个好方法”? –