1

你好,我在 json 中有一个看起来像这样的响应

{
    "el": {
        "reviewed_percentage": "0%",
        "completed": "16%",
        "untranslated_words": 8,
        "last_commiter": "zaabalonso",
        "reviewed": 0,
        "translated_entities": 1,
        "translated_words": 1,
        "last_update": "2012-07-06 13:08:10",
        "untranslated_entities": 5
    },
    "en": {
        "reviewed_percentage": "0%",
        "completed": "100%",
        "untranslated_words": 0,
        "last_commiter": "zaabalonso",
        "reviewed": 0,
        "translated_entities": 6,
        "translated_words": 9,
        "last_update": "2012-07-06 12:28:48",
        "untranslated_entities": 0
    },
    "gl_ES": {
        "reviewed_percentage": "0%",
        "completed": "33%",
        "untranslated_words": 7,
        "last_commiter": "zaabalonso",
        "reviewed": 0,
        "translated_entities": 2,
        "translated_words": 2,
        "last_update": "2012-07-06 13:06:46",
        "untranslated_entities": 4
    }
}

我怎样才能像使用javascript那样转换它

[{
            "language"="el",
            "reviewed_percentage": "0%",
            "completed": "16%",
            "untranslated_words": 8,
            "last_commiter": "zaabalonso",
            "reviewed": 0,
            "translated_entities": 1,
            "translated_words": 1,
            "last_update": "2012-07-06 13:08:10",
            "untranslated_entities": 5},
........etc.
]
4

1 回答 1

1

您可以遍历 JSON 数据并使用您想要的格式创建一组新数据,例如使用下面的伪代码(假设 oldJSON 被分配为发布的 JSON 响应)

var newData = [];
for ( var s in oldJSON )
{
    var data = oldJSON[s];
    data.language = s;
    newData.push(data);
}
于 2012-07-14T16:12:51.437 回答