将json数据存储在数据库和json对象的格式中

时间:2020-12-19 16:58:43

This is my Json object for products which is stored in database. This json object is also storing another json object with images.
1.question: Is this the correct way of storing data about products in database or should be images stored separately?
2.question: Is format of this json object correct, i'm especially interested in sub json "images"? 3.question: How should JSON object look like if sub Json "images" would have like some json index array, where index would be the position of image

这是我的Json对象,用于存储在数据库中的产品。这个json对象还存储了另一个带有图像的json对象。 1.问题:这是在数据库中存储产品数据的正确方法,还是应该单独存储图像? 2.question:这个json对象的格式是否正确,我对sub json“images”特别感兴趣? 3.question:如果子Json“images”会有一些json索引数组,JSON对象应该怎么样,其中index就是图像的位置

{
  "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}
             ]"
   }

I'm askin this because currently i have problems printing JSON data. All i can do is call products[0].images, but if i try to select first thumb picture i fail. i Have tried many variations and nothing is working

If you need any additional question, please let me know and i will provide.
Thanks in advance

我问这个是因为目前我在打印JSON数据时遇到问题。我所能做的只是呼叫产品[0] .images,但如果我尝试选择第一个拇指图片我失败了。我尝试了很多变化,没有任何工作如果您需要任何其他问题,请告诉我,我会提供。提前致谢

2 个解决方案

#1


1  

I would recommend giving this article a read from tutsplus

我建议从tutsplus读取这篇文章

Copy and past the following at jsonlint to validate,

复制并通过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
    }]
}

#2


1  

Your JSON seems to be invalid, when you want to test your json structure sites like this are very helpful.

您的JSON似乎无效,当您想要测试您的json结构网站时,这样会非常有帮助。

edit: In your case a valid JSON would be:

编辑:在您的情况下,有效的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'}]" }

{“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 v​​oluptates numquam。 “,”date_c“:”2015-12-31 02:06:32“,”date_u“:”null“,”id_category“:”46“,”id_user“:”123“,”别名“:”rippin-工会“,”活跃“:”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  

I would recommend giving this article a read from tutsplus

我建议从tutsplus读取这篇文章

Copy and past the following at jsonlint to validate,

复制并通过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
    }]
}

#2


1  

Your JSON seems to be invalid, when you want to test your json structure sites like this are very helpful.

您的JSON似乎无效,当您想要测试您的json结构网站时,这样会非常有帮助。

edit: In your case a valid JSON would be:

编辑:在您的情况下,有效的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'}]" }

{“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 v​​oluptates numquam。 “,”date_c“:”2015-12-31 02:06:32“,”date_u“:”null“,”id_category“:”46“,”id_user“:”123“,”别名“:”rippin-工会“,”活跃“:”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'}]“}