当前位置:网站首页>一次采集JSON解析错误的修复
一次采集JSON解析错误的修复
2022-06-29 17:28:00 【是有头发的程序猿】
两段采集来的JSON格式:更多API接口测试请点击注册
一:
{“hwgOnlineId”:“554312”, “jiwuChatId”:“”, “phoneCategoryId”:“20006”, “cuxiaoSeq”:{voucherTitle:1,lhvoucherTitle:2,isXYuanNItemTitle:3,taogouyhTitle:4,giftTitle:5,limitGifts:6,ordersGifts:7,jrPromTitle:8,purchaseTitle:9,couponTitle:10,newcouponTitle:11,yfbTitle:12,rxfTitle:13,scodeTitle:14,pointTitle:15,freightfreeTitle:16,govTitle:17,jnbtTitle:18}, “blackCategoryCode”:“R9010501”}
二:
{“pic”:“//imgservice.suning.cn/uimg1/b2c/image/rX4cM65dyr_4kndNFwLEgA.jpg_400w_400h_4e”,
“itemDomain”:“//”+document.location.hostname,
“resRoot”:“//script.suning.cn/project/pdsWeb”,
“shopCount”:1,
“sslStoreCode”:“”,
“addCartNumLimit”:“199”,
“favoriteStatusSwitch”:“1” == “1”,
“thirdEVoucherFlag”:“”,
“specialSSLFlag”:“”,
“sslLabelText” : “苏宁服务”}
直接使用PHP的json_decode报错
解决思路:
1、手动格式化,将所有","换行
2、半分法删除内容定位报错的代码行
3、找到问题行后过滤格式处理
4、对于json格式中掺杂了javascript代码的情况还可以直接使用v8js引擎处理
解决方案一(修复格式):
$str = file_get_contents(‘test.txt’);
KaTeX parse error: Undefined control sequence: \* at position 23: …reg_replace('@/\̲*̲[^/]+\*/@isU','…str);
s t r = s t r r e p l a c e ( ′ " + d o c u m e n t . l o c a t i o n . h o s t n a m e ′ , ′ " ′ , str = str_replace('"+document.location.hostname','"', str=strreplace(′"+document.location.hostname′,′"′,str);
s t r = s t r r e p l a c e ( ′ " 1 " = = " 1 " ′ , ′ t r u e ′ , str = str_replace('"1" == "1"','true', str=strreplace(′"1"=="1"′,′true′,str);
j s o n = j s o n d e c o d e ( json = json_decode( json=jsondecode(str);
if(!$json) j s o n = j s o n 2 a r r a y ( json = json2array( json=json2array(str);
var_dump(getJsJSON($json));
解决方案二(使用PHP-V8JS扩展):
//以JavaScript环境执行JS
function getJsJSON($str){
$v8 = new V8Js();
KaTeX parse error: Expected '}', got 'EOF' at end of input: …}} a={ str}
return JSON.stringify(a);
}
b = getJsJSON()
";
try {
//传递参数给js
// $v8->str = $str;
//执行js
$code = v 8 − > e x e c u t e S t r i n g ( v8->executeString( v8−>executeString(func);
//清空对象,垃圾回收。
unset($v8);
} catch (V8JsScriptException KaTeX parse error: Expected '}', got 'EOF' at end of input: … dump(e->getMessage());
dump( e − > g e t J s S o u r c e L i n e ( ) ) ; d u m p ( e->getJsSourceLine()); dump( e−>getJsSourceLine());dump(e->getJsTrace());
// dump(KaTeX parse error: Expected 'EOF', got '}' at position 11: e); }̲ if(code) c o d e = j s o n d e c o d e ( code=json_decode( code=jsondecode(code,true);
return $code;
}
j s = f i l e g e t c o n t e n t s ( ′ t e s t . t x t ′ ) ; v a r d u m p ( g e t J s J S O N ( js = file_get_contents('test.txt'); var_dump(getJsJSON( js=filegetcontents(′test.txt′);vardump(getJsJSON(js));
边栏推荐
- 开源仓库贡献 —— 提交 PR
- 设置双击运行 jar 文件
- How to solve the 2003 error of MySQL in Linux
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
- C语言练习----指针字符串、链表
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- Development of freedom free agreement pledge mining system
- 微信小程序开发储备知识
- 2022年软件评测师考试大纲
- Error:Connection refused: connect
猜你喜欢
随机推荐
mysql支持外键吗
How to solve the 2003 error of MySQL in Linux
Kubernetes deployment dashboard (Web UI management interface)
【Try to Hack】Cookie和Session
mysql数据库扫盲,你真的知道什么是数据库嘛
ICML 2022 | 基于解耦梯度优化的可迁移模仿学习方法
自动收售报机
Tencent cloud released orbit, an automated delivery and operation and maintenance product, to promote enterprise applications to be fully cloud native
R语言dplyr包filter函数通过组合逻辑(与逻辑)过滤dataframe数据中的数据、其中一个字段的内容等于指定向量中的其中一个,并且另外一个字段值大于某一阈值
[the sixth operation of modern signal processing]
Pancakeswap Technology: development principle of gripper robot system
Online sql to CSV tool
R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
Multi mode concurrent implementation of tortoise and rabbit race in go language
@Component与@Configuration区别
NAACL 2022 | 机器翻译SOTA模型的蒸馏
Automatic vending machine
线段树、树状数组模板(复制粘贴确实好用)
mysql如何查询表的字符集编码
Go语言多方式并发实现龟兔赛跑

![[the sixth operation of modern signal processing]](/img/49/7844a00077e56fd4d73e3ba515f8a6.png)






