当前位置:网站首页>一次采集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));
边栏推荐
- 在线SQL转CSV工具
- 关于harbor私有仓库忘记登录密码
- [R language data science]: Text Mining (taking Trump's tweet data as an example)
- linux中mysql 1045错误如何解决
- High landing pressure of "authorization and consent"? Privacy computing provides a possible compliance "technical solution"
- mysql数据库扫盲,你真的知道什么是数据库嘛
- 正则表达式
- 2022 software evaluator examination outline
- Shenzhen internal promotion | Shenzhen Institute of computing science recruits assistant machine learning Engineer (school recruitment)
- R语言dplyr包filter函数通过组合逻辑(与逻辑)过滤dataframe数据中的数据、其中一个字段的内容等于指定向量中的其中一个,并且另外一个字段值大于某一阈值
猜你喜欢

PCB板框的绘制——AD19

微信小程序开发储备知识

mysql如何查询表的字符集编码

OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置

【R语言数据科学】:文本挖掘(以特朗普推文数据为例)

@Component与@Configuration区别

序列检测器
Master slave replication of MySQL

Function calculation asynchronous task capability introduction - task trigger de duplication
![[the sixth operation of modern signal processing]](/img/49/7844a00077e56fd4d73e3ba515f8a6.png)
[the sixth operation of modern signal processing]
随机推荐
NAACL 2022 | 机器翻译SOTA模型的蒸馏
R language uses user-defined functions to write deep learning linear activation functions and visualize linear activation functions
sequential detector
固定资产管理系统让企业动态掌握资产情况
2020版KALI安装教程
为什么信息化 ≠ 数字化?终于有人讲明白了
外部自动(PLC启动机器人)
Kubernetes部署Dashboard(WEB UI管理界面)
设置双击运行 jar 文件
OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置
Sectigo ov pan domain name certificate is 1590 yuan a year easy to use
适合中小企业的项目管理系统有哪些?
KUKA子程序/函数怎么建立和使用方法
腾讯云发布自动化交付和运维产品Orbit,推动企业应用全面云原生化
Self taught structure (small turtle C language)
Development of freedom free agreement pledge mining system
Graduation season | Huawei experts teach interview tips: how to get a high salary offer from a large factory?
@Component与@Configuration区别
【Oracle】基础知识面试题
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