Jq 操作json

摘要:
=="string"||!data){returnnull;}data=jQuery.trim(data);if(/^[],:{}s]*$/.test(data.replace(/\(?:["\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\]*"|true|false|null|-?d+(?:.d*)?(?:[eE][+-]?d+)?/g,"]").replace(/(?:^|:|,)(?:s*[)+/g,""))){returnwindow.JSON&&window.JSON.parse?window.JSON.parse(data):(newFunction("return"+data))();}else{jQuery.error("InvalidJSON:"+data);}}
//1.比较古老的方法:
functionstrToJson(str){
varjson=eval('('+str+')');
returnjson;
}
//3.IE67不支持的json对象方法:
functionstrToJson(str){
returnJSON.parse(str);
}
//2.比较常用的方法:
functionstrToJson(str){
return(newFunction("return"+str))();
}
//4.jQuery提供的方法:
parseJSON:function(data){
if(typeofdata!=="string"||!data){
returnnull;
}
data=jQuery.trim(data);
if(/^[],:{}s]*$/.test(data.replace(/\(?:["\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\]*"|true|false|null|-?d+(?:.d*)?(?:[eE][+-]?d+)?/g,"]").replace(/(?:^|:|,)(?:s*[)+/g,""))){
returnwindow.JSON&&window.JSON.parse?window.JSON.parse(data):(newFunction("return"+data))();
}else{
jQuery.error("InvalidJSON:"+data);
}
}

免责声明:文章转载自《Jq 操作json》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Node.js连接RabbitMQ,断线重连,动态绑定routing keywinhex教程 转 武胜下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

微信内置浏览器清理缓存方法

给出清除微信浏览器缓存的终极方法:您可以尝试可能不会成功的方法:window。name){varstr=Math.random().toString(36).substr(2);S='+str;//兼容微信浏览器刷新窗口。name='isread';}<3.Android可以打开此网站以清除cache://debugx5.qq。com公司/☆☆...

Python3 读取和写入excel

/py_工作/销售/包括/天气。csv'_工作簿函数读取并返回所有工作表● 以列表形式读取_仅:判断是否读取_仅以模式打开Excel文档● 编码:...

C#探秘系列(十)WPF:打开文件选择器选择文件并保存

//此为点击按钮的监听事件,点击按钮弹出文件选择器privatevoidimageButton_Click(objectsender,RoutedEventArgse){vardialog=newOpenFileDialog();dialog.Filter=".jpg|*.jpg|.png|*.png|.jpeg|*.jpeg";if(dialog.Show...

c++ 发送消息,模拟拖拽文件

=NULL)28{29LPSTRpszRemote=VirtualAllocEx;30if31{32::SendMessage;33bResult=TRUE;34}35}36}3738if39{40delete[]pBuf;41pBuf=NULL;42}43 returnbResult;44}在调用此函数之前,首先打开接受拖动的进程ShellExecute;...

java.net.URISyntaxException的解决办法

直接采用Stringurl=“http:count=1”;HttpGethttpget=新的HttpGet(url);HttpResponseresponse=client.execute(httpget);例如,“|”&因此,不能直接使用String而不是URI来访问。然后我们可以使用URL生成URI的方法来解决这个问题。代码如下:URLu...

Python-正则

,三:量词*重复0次或多次{0,}+重复一次或多次{1,}?重复0或1次{1,0}{n}重复n次{n}{n,}重复n次,或更多次{n,m}将n次重复到m次Escape:如果字符串中有特殊字符要匹配,请在常规字符和字符串前面添加r。如果特殊字符在字符组中,则它们是匹配的特殊字符,但为了记忆,匹配时会转义所有特殊字符。...