0

我有以下 JSON:

 {
"folder": [
    {
        "$": {
            "id": "471841542",
            "name": "Manajemen Pemasaran",
            "description": "",
            "user_id": "186868958",
            "shared": "1",
            "shared_link": "https://www.box.com/s/b0nupgg8boe25nyfz781",
            "permissions": "kcfgtedopnhsuvy",
            "size": "2258167",
            "file_count": "5",
            "created": "1352203782",
            "updated": "1352260971"
        },
        "tags": [
            {}
        ]
    },
    {
        "$": {
            "id": "469509910",
            "name": "C++",
            "description": "",
            "user_id": "186868958",
            "shared": "1",
            "shared_link": "https://www.box.com/s/byyidt02k4sglbuvxlw3",
            "permissions": "kcfgtedopnhsuvy",
            "size": "1322331",
            "file_count": "128",
            "created": "1352101667",
            "updated": "1352203670"
        },
        "tags": [
            {}
        ]
    },
    {
        "$": {
            "id": "469476618",
            "name": "Default Sync Folder",
            "description": "",
            "user_id": "186868958",
            "shared": "0",
            "shared_link": "",
            "permissions": "kcfgtedopnhsuvy",
            "size": "49509",
            "file_count": "1",
            "created": "1352098703",
            "updated": "1352098713"
        },
        "tags": [
            {}
        ]
    },
    {
        "$": {
            "id": "469469972",
            "name": "My Box Files",
            "description": "",
            "user_id": "186868958",
            "shared": "0",
            "shared_link": "",
            "permissions": "kcfgtedopnhsuvy",
            "size": "32426",
            "file_count": "1",
            "created": "1352097877",
            "updated": "1352097977"
        },
        "tags": [
            {}
        ]
    }
 ]
 }

我希望它变成这样:

 {
"folder": [{
            "id": "471841542",
            "name": "Manajemen Pemasaran",
            "description": "",
            "user_id": "186868958",
            "shared": "1",
            "shared_link": "https://www.box.com/s/b0nupgg8boe25nyfz781",
            "permissions": "kcfgtedopnhsuvy",
            "size": "2258167",
            "file_count": "5",
            "created": "1352203782",
            "updated": "1352260971"
                "tags": [
            {}
        ]
    },
    {
            "id": "469509910",
            "name": "C++",
            "description": "",
            "user_id": "186868958",
            "shared": "1",
            "shared_link": "https://www.box.com/s/byyidt02k4sglbuvxlw3",
            "permissions": "kcfgtedopnhsuvy",
            "size": "1322331",
            "file_count": "128",
            "created": "1352101667",
            "updated": "1352203670",
                "tags": [
            {}
        ]
    },
    {
            "id": "469476618",
            "name": "Default Sync Folder",
            "description": "",
            "user_id": "186868958",
            "shared": "0",
            "shared_link": "",
            "permissions": "kcfgtedopnhsuvy",
            "size": "49509",
            "file_count": "1",
            "created": "1352098703",
            "updated": "1352098713",
            "tags": [
            {}
        ]
    },
    {
        "$": {
            "id": "469469972",
            "name": "My Box Files",
            "description": "",
            "user_id": "186868958",
            "shared": "0",
            "shared_link": "",
            "permissions": "kcfgtedopnhsuvy",
            "size": "32426",
            "file_count": "1",
            "created": "1352097877",
            "updated": "1352097977"
                "tags": [
            {}
        ]
    }
 ]
 }

有没有办法从上面的 JSON 中删除 $?

4

1 回答 1

1

这应该会创建您想要的结果:

var json = { ... };    // your JSON data
var newJson = { folder: [] };

for (var i = 0, l = json.folder.length; i < l; ++i) {
    var tmp = json.folder[i].$;
    tmp.tags = json.folder[i].tags;
    newJson.folder.push(tmp);
}

console.log(newJson);
于 2012-11-12T13:20:41.377 回答