解析JSON对象以获取文件位置

时间:2022-08-26 11:49:56

i am new to JSON. Here i am facing problem how to get file location from JSON object, i am using javascript to parse the json

我是JSON的新手。这里我面临着如何从JSON对象获取文件位置的问题,我使用javascript来解析json

{
"_embedded": {
    "binaries": [
        {
            "fileLocation": "http://images.clipartpanda.com/sports-equipment-clipart-black-and-white-soccer-ball-hi.png",
            "username": "testuser3",
            "description": "The company required the 28-year-old's help on a matter the directors felt could affect the share price: its Wikipedia page. Short, uninteresting .",
            "createdAt": "2015-02-01T21:47:07.000+0000",
            "updatedAt": "2015-02-01T22:42:16.000+0000"
        },
        {
            "fileLocation": "http://images.clipartpanda.com/sports-equipment-clipart-black-and-white-soccer-ball-hi.png",
            "username": "Sumanth",
            "description": "Sample",
            "createdAt": "2015-02-23T21:37:13.000+0000",
            "updatedAt": "2015-02-23T21:43:11.000+0000"
        },
        {
            "fileLocation": "http://images.clipartpanda.com/sports-equipment-clipart-black-and-white-soccer-ball-hi.png",
            "username": "as",
            "description": "as",
            "createdAt": "2015-02-02T22:46:00.000+0000",
            "updatedAt": "2015-02-27T22:06:18.000+0000"
        }
    ]
}

}

i want to read all file locations from JSON object . Can anyone help me. Thanks in advance

我想从JSON对象中读取所有文件位置。谁能帮我。提前致谢

1 个解决方案

#1


1  

The way you are trying to access fileLocation looks right:

您尝试访问fileLocation的方式看起来是正确的:

data._embedded.binaries[1].fileLocation

Before that, to parse your data use:

在此之前,要解析您的数据使用:

parsed = JSON.parse(data);

Here's a fiddle: http://jsfiddle.net/01aL5upc/ Note that I did remove whitespace and the apostrophe in 28-year-old's in the fiddle, to put it in to a string rather than an ajax request.

这是一个小提琴:http://jsfiddle.net/01aL5upc/请注意,我确实删除了28岁的小提琴中的空格和撇号,将其放入字符串而不是ajax请求中。

#1


1  

The way you are trying to access fileLocation looks right:

您尝试访问fileLocation的方式看起来是正确的:

data._embedded.binaries[1].fileLocation

Before that, to parse your data use:

在此之前,要解析您的数据使用:

parsed = JSON.parse(data);

Here's a fiddle: http://jsfiddle.net/01aL5upc/ Note that I did remove whitespace and the apostrophe in 28-year-old's in the fiddle, to put it in to a string rather than an ajax request.

这是一个小提琴:http://jsfiddle.net/01aL5upc/请注意,我确实删除了28岁的小提琴中的空格和撇号,将其放入字符串而不是ajax请求中。