javascript - Problem with native js ajax getting data and converting it into json object
高洛峰
高洛峰 2017-05-19 10:38:41
0
1
382

Use ajax written natively in js to obtain a data list, and the order is normal

xmlHttp.responseText The order here is normal

But when I convert the json string into a json object, the order is not the original order

var json = eval('(' + xmlHttp.responseText + ')');

Is there any way to maintain the original output order after conversion?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all (1)
phpcn_u1582

I don’t quite understand, what do you mean? Has the data order changed? ?
Actually, there are several ways toJson, you can try them all.

// 1 function toJson(json){ return json ? (new Function("return "+ json))() : {} } toJson(xmlHttp.responseText) // 2 JSON.parse(xmlHttp.responseText) // 3 就是你那种
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!