json产品数据存储区创建 [英] json product data store creating
本文介绍了json产品数据存储区创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问一个关于JSON的问题.
I wanna ask you a question about JSON.
我想按类别区分产品.如何用JSON编写?
I want to differentiate product by categories. How can I write that in JSON?
{"products":
{"category" : "computer"[
{"brand" : "sony"
"price" : "$1000"},
{"brand" : "acer"
"price" : "$400"},]}
,
{"category" : "cell phone"[
{"brand" : "iphone"
"price" : "$800"},
{"brand" : "htc"
"price" : "$500"},]}
}
推荐答案
我认为您可能需要这样的东西:
I think you may need something like this:
{"products":
{"computer":
[
{"brand" : "sony",
"price" : "$1000"},
{"brand" : "acer",
"price" : "$400"}
],
"cell phone":
[
{"brand" : "iphone",
"price" : "$800"},
{"brand" : "htc",
"price" : "$500"}
]
}
}
通过使用类别作为JSON对象中的键,您可以轻松访问该类别中的所有产品,例如:
By using the category as the key in the JSON object you can easily access all products in that category, for example:
>>> data['products']['computer']
[{'brand': 'sony', 'price': '$1000'}, {'brand': 'acer', 'price': '$400'}]
如有必要,您还可以在顶级JSON对象中添加类别列表,以便了解可用的类别:
If necessary, you can also add a list of categories to top level JSON object so that you know what categories are available:
{"products": {...},
"categories": ["computer", "cell phone"]
}
这篇关于json产品数据存储区创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文