当前位置:网站首页>一次采集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));
边栏推荐
- 2022年软件评测师考试大纲
- How to solve MySQL 1045 error in Linux
- Online text digit recognition list summation tool
- Bags of Binary Words for Fast Place Recognition in Image Sequenc
- Browser large screen capture
- R language uses GLM of mass package The Nb function establishes the negative binomial generalized linear model, and the summary function obtains the summary statistical information of the negative bin
- 传承中华美德,关注中老年大健康,育润奶粉敬老情浓
- Younger sister Juan takes you to learn JDBC - 2-day dash Day1
- 底层内功修养
- KUKA子程序/函数怎么建立和使用方法
猜你喜欢

Redis principle - sorted set (Zset)

0基础自学STM32(野火)——使用寄存器点亮LED——GPIO功能框图讲解

SpingMVC请求和响应

Mysql中锁的使用场景是什么

mysql在linux中2003错误如何解决

PCB frame drawing - ad19

Collaborative development of epidemic home outsourcing project 𞓜 community essay solicitation

What are the usage scenarios for locks in MySQL

How to create and delete MySQL triggers

mysql. What is the concept of sock
随机推荐
浏览器大尺寸截屏
剑指 Offer 13. 机器人的运动范围 (BFS)
Redis bloom filter and cuckoo filter
0基础自学STM32(野火)——使用寄存器点亮LED——GPIO功能框图讲解
开源仓库贡献 —— 提交 PR
Redis principle - sorted set (Zset)
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用exp函数和coef函数获取模型所有变量的事件密度比(Incidence Density Ratio,IDR)并解读
Error:Connection refused: connect
R language uses GLM of mass package The Nb function establishes the negative binomial generalized linear model, and the summary function obtains the summary statistical information of the negative bin
SAAS 服务的优势都有哪些
Does MySQL support foreign keys
深圳内推 | 深圳计算科学研究院招聘机器学习助理工程师(校招)
regular expression
LeetCode 每日一题——535. TinyURL 的加密与解密
Browser large screen capture
The fixed assets management system enables enterprises to dynamically master assets
LSB hidden items of stream carrier based on assembly implementation
Sectigo ov pan domain name certificate is 1590 yuan a year easy to use
What is the MySQL query view command
R语言epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、aggregate.data.frame函数包含缺失值的情况下分组统计结果为NA