通过JSON数组迭代:获取参数的名称

我正在通过我的JSON响应进行迭代。 我有一些带有id的HTML元素作为参数名称。

例如,我的JSON响应包含一个"costcenter":"1234" ,并且有一个带有id costcenter元素。

现在,我没有为每个id编写语句,而是试图通过JSON数组进行迭代,并自动读取它的名称。

这就是我得到的

 $(".dataset").click(function() { changeid = this.id; $.ajax({ url: "source", dataType: "json", contentType: "application/json; charset=utf-8", data: { id: changeid }, success: function(data) { // How to get the name of the parameter, and then read it's value? } }) }) 

JSON看起来像这样,它只是一个维度和1个结果集: {"changeid":"1","costcenter":"478","manager":"John Smith"}

如果我理解你的问题,你在成功函数中需要类似的东西:

 for (var key in data) { $('#'+key).html(data[key]); }