【数据准备-数据源】特殊JSON该如何解析
本帖最后由 James.Lv 于 2023-1-5 18:17 编辑相信大家在使用wyn中json数据源时,觉得非常便捷。对于标准化json解析中也能得心应手的解决,但是在一些特定业务中,返回的json并不是wyn中理想的json模样。那么我们该如何去处理?
先来个练习题,看看遇到这种json我们该如何下手呢?本来可以愉快的下班的,却遇到了这么个问题。其实json也很无辜,我也想成为你想要的样子,可是臣妾做不到啊。
其实此类json我们在教程中已经做了比较详细的解释,但是如果对jsonpath解析掌握度不够的话,那么帮助手册有==无。大家认真看以下就是教程了,干货来了:案例1:jsonA.json 文件内容:{"metas":{"A":{"align":"left","attrKeys":"","cname":" "}},"__sys__":{"msg":"执行成功","status":0},"data":[["A","B"],["12688","5731.00"],["8920","32667.00"],["15903","31755.00"],["16477","5228.00"],["14140","29712.00"],["13391","19130.00"],["17487","26323.00"],["22135","31505.00"],["10635","28000.00"],["24291","19201.00"],["16959","25258.00"]],"__version__":"1.0","__blocks__":{}}操作方式:select * from UnwindJson(@source,'$.data') tmp with(A varchar '$.',B varchar '$.')解析结果:
案例2:jsonB.json 文件内容{"__tarAppEname__":"ww","__sys__":{"msg":"执行成功","status":0},"__version__":"2.0","urlAdress":"","__blocks__":{"result":{"meta":{"columns":[{"pos":0,"name":"BRANCH_CNAME","descName":" "},{"pos":1,"name":"DATE","descName":" "},{"pos":2,"name":"POST_CODE","descName":" "},{"pos":3,"name":"PERSON_NAME","descName":" "}]},"attr":{"offset":0,"limit":10},"rows":[["工厂","202008","BB","王刚"],["工厂","202008","AA","马冲"],["工厂","202008","CC","张飞"],["工厂","202008","DD","叶开"]]}}}操作方式:select * from UnwindJson(@source,'$.__blocks__.result.rows') tmp with(
BRANCH_CNAME varchar '$.',DATE varchar '$.',POST_CODE varchar '$.',PERSON_NAME varchar '$.')解析结果:
在案例1中,我们看到 $.data 这么个语句,这个意思是,读取包括第一行到最后一行数据。
通过以上方式,我们就可以轻松的将json转换为我们想要的二维表格式。大家还有什么需要转换的json格式,可以共同讨论。
页:
[1]