文章内容

2020/5/14 18:49:05,作 者: 黄兵

json理解

最近在Angular里面需要使用到json返回数据,自己写了一个json文件,以前直接使用,没有发现问题。但是今天自己写,有很多问题,经过研究终于搞清楚了。

首先参考json官方网站:介绍 JSON

可以看到Json的一些数据类型(对象,数组,值、字符串、数值)。

下面是一个json文件的具体内容:

{
    "phone_number_list":[
        {
            "phone_number":"14433908875",
            "area_code":"+1",
            "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
            "last_time":"2020/5/14 15:19",
            "sms_count":"1000",
            "create_time":"2020/5/14 15:19",
            "state":"live",
            "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/done_40dp.png"
        },
        {
            "phone_number":"14433908875",
            "area_code":"+1",
            "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
            "last_time":"2020/5/14 15:19",
            "sms_count":"1000",
            "create_time":"2020/5/14 15:19",
            "state":"disable",
            "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/clear_40dp.png"
        },
        {
            "phone_number":"14433908875",
            "area_code":"+1",
            "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
            "last_time":"2020/5/14 15:19",
            "sms_count":"1000",
            "create_time":"2020/5/14 15:19",
            "state":"disable",
            "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/clear_40dp.png"
        },
        {
            "phone_number":"14433908875",
            "area_code":"+1",
            "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
            "last_time":"2020/5/14 15:19",
            "sms_count":"1000",
            "create_time":"2020/5/14 15:19",
            "state":"disable",
            "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/clear_40dp.png"
        },
        {
            "phone_number":"14433908875",
            "area_code":"+1",
            "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
            "last_time":"2020/5/14 15:19",
            "sms_count":"1000",
            "create_time":"2020/5/14 15:19",
            "state":"disable",
            "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/clear_40dp.png"
        },
        {
            "phone_number":"14433908875",
            "area_code":"+1",
            "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
            "last_time":"2020/5/14 15:19",
            "sms_count":"1000",
            "create_time":"2020/5/14 15:19",
            "state":"disable",
            "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/clear_40dp.png"
        }
    ]
}

通过json.cn,可以看到:

{
    "phone_number":"14433908875",
    "area_code":"+1",
    "country_flag":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/america_flag_344x194dp.png",
    "last_time":"2020/5/14 15:19",
    "sms_count":"1000",
    "create_time":"2020/5/14 15:19",
    "state":"disable",
    "state_img":"https://pdflib-1253677444.cos.ap-beijing-1.myqcloud.com/sms_resouce/static/images/sms_america/clear_40dp.png"
}

这是一个对象,截图如下:

phone_number_list下面的所有子元素,组成了一个数组:

json简单说就是javascript中的对象和数组,所以这两种结构就是对象和数组两种结构,通过这两种结构可以表示各种复杂的结构

具体介绍可以看看这篇文章:什么是Json


参考资料:

1、https://www.json.org/json-zh.html

2、什么是Json


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - json理解

分享到:

发表评论

评论列表