2016-10-13 00:16:48 点击量:18 标签: 收藏本文
ajax请求php返回一个数组格式的字符串,情况特殊不能修改php使其返回json格式,只有拿js来解析了.代码如下:
- function dataTrans( str )
- {
- var obj = {};
- strstr = str.replace( /^Array\s*\(/,'' ).replace( /\)\s*$/,'' );
- str.replace( /\[(\w+)\]\s+=>((?:[\S\s](?!\[(\w+)\]\s+=>))+)/g,function( m,$1,$2 )
- {
- obj[$1] = $2;
- });
- return obj;
- }