这是我的Json对象,用于存储在数据库中的产品。这个json对象还存储了另一个带有图像的json对象 1.问题:这是在数据库中存储产品数据的正确方法,还是应该单独存储图像? 2.question:这个json对象的格式是否正确,我对sub json“images”特别感兴趣? 3.问题:如果子Json“images”会有一些json索引数组,其中index将是图像的位置
,JSON对象应该怎么样?{
"id_product": "1000",
"name": "Rippin Unions",
"description": "Vel aut sed neque enim illum mollitia. Molestias aperiam qui dolorem qui est. Dolore cumque dolore formatedtempore ipsum. Veniam molestiae laudantium voluptates numquam.",
"date_c": "2015-12-31 02:06:32",
"date_u": null,
"id_category": "46",
"id_user": "123",
"alias": "rippin-unions",
"active": "1",
"images": "[
{thumbImage:"http://lorempixel.com/250/150/?27403",image:"http://lorempixel.com/1024/768/?28526",position:4},
{thumbImage:"http://lorempixel.com/250/150/?25207",image:"http://lorempixel.com/1024/768/?73566",position:1},
{thumbImage:"http://lorempixel.com/250/150/?26960",image:"http://lorempixel.com/1024/768/?72686",position:0},
{thumbImage:"http://lorempixel.com/250/150/?25168",image:"http://lorempixel.com/1024/768/?22297",position:2},
{thumbImage:"http://lorempixel.com/250/150/?94897",image:"http://lorempixel.com/1024/768/?94418",position:3}
]"
}
我问这个是因为目前我在打印JSON数据时遇到问题。
我所能做的就是拨打products[0].images
,但如果我尝试选择第一张拇指图片,我就会失败。我尝试了很多变化,没有任何工作
如果您还有其他问题,请告诉我,我会提供。
提前致谢
答案 0 :(得分:1)
当您想要测试json结构时,您的JSON似乎无效,this这样的网站非常有帮助。
编辑:在您的情况下,有效的JSON将是:
{
"id_product": "1000",
"name": "Rippin Unions",
"description": "Vel aut sed neque enim illum mollitia. Molestias aperiam qui dolorem qui est. Dolore cumque dolore formatedtempore ipsum. Veniam molestiae laudantium voluptates numquam.",
"date_c": "2015-12-31 02:06:32",
"date_u": "null",
"id_category": "46",
"id_user": "123",
"alias": "rippin-unions",
"active": "1",
"images": "[{'thumbImage': 'http://lorempixel.com/250/150/?27403\','image': 'http://lorempixel.com/1024/768/?28526\','position': '4'},{'thumbImage': 'http://lorempixel.com/250/150/?25207\','image':'http: //lorempixel.com/1024/768/?73566\','position':'1'}]"
}
答案 1 :(得分:1)
我建议您阅读本文tutsplus
在jsonlint复制并通过以下内容进行验证,
{
"id_product": 1000,
"name": "Rippin Unions",
"description": "Vel aut sed neque enim illum mollitia. Molestias aperiam qui dolorem qui est. Dolore cumque dolore formatedtempore ipsum. Veniam molestiae laudantium voluptates numquam.",
"date_c": "2015-12-31 02:06:32",
"date_u": null,
"id_category": 46,
"id_user": 123,
"alias": "rippin-unions",
"active": 1,
"images": [{
"thumbImage": "http://lorempixel.com/250/150/?27403",
"image": "http://lorempixel.com/1024/768/?28526",
"position": 4
}, {
"thumbImage": "http://lorempixel.com/250/150/?25207",
"image": "http://lorempixel.com/1024/768/?73566",
"position": 1
}, {
"thumbImage": "http://lorempixel.com/250/150/?26960",
"image": "http://lorempixel.com/1024/768/?72686",
"position": 0
}, {
"thumbImage": "http://lorempixel.com/250/150/?25168",
"image": "http://lorempixel.com/1024/768/?22297",
"position": 2
}, {
"thumbImage": "http://lorempixel.com/250/150/?94897",
"image": "http://lorempixel.com/1024/768/?94418",
"position": 3
}]
}