当前位置:网站首页>一次采集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));
边栏推荐
- MySQL触发器如何创建与删除
- 0 basic self-study STM32 (wildfire) - register lit LED
- 0基础自学STM32(野火)——寄存器点亮LED
- mysql查询视图命令是哪个
- C语言练习----指针字符串、链表
- 卷妹带你学jdbc—2天冲刺Day1
- OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置
- Bottom level internal skill cultivation
- What are the project management systems suitable for small and medium-sized enterprises?
- 固定资产管理系统让企业动态掌握资产情况
猜你喜欢

SpingMVC请求和响应

The soft youth under the blessing of devcloud makes education "smart" in the cloud

How to solve the 2003 error of MySQL in Linux

从Mpx资源构建优化看splitChunks代码分割

mysql.sock的概念是什么

mysql数据库扫盲,你真的知道什么是数据库嘛

SLAM中的子图

Bottom level internal skill cultivation

mysql在linux中2003错误如何解决

Redis principle - sorted set (Zset)
随机推荐
Younger sister Juan takes you to learn JDBC - 2-day dash Day1
How to use interrupt
Redis principle - sorted set (Zset)
Multi mode concurrent implementation of tortoise and rabbit race in go language
为什么信息化 ≠ 数字化?终于有人讲明白了
[R language data science]: Text Mining (taking Trump's tweet data as an example)
ICML 2022 | 基于解耦梯度优化的可迁移模仿学习方法
从Mpx资源构建优化看splitChunks代码分割
@Difference between component and @configuration
Bottom level internal skill cultivation
Does MySQL support foreign keys
The soft youth under the blessing of devcloud makes education "smart" in the cloud
R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses exp function and coef function to ob
What role does the supply chain management system play in the supply chain scenario?
序列检测器
How to create and delete MySQL triggers
epoll分析
R语言使用自定义函数编写深度学习线性激活函数、并可视化线性激活函数
自学结构体(小甲鱼c语言)
L'intercepteur handlerinterceptor personnalisé permet l'authentification de l'utilisateur