首页 > 解决方案 > R中的JSON格式拒绝解析?

问题描述

这是我的玩具 JSON:

"[[143828095,86.82525,78.50037,0.011764707,1.0,1,1],  
[143828107,86.82525,78.50037,0.015686275,1.0,1,0], 
[143828174,84.82802,83.49646,0.015686275,1.0,1,0], 
[143828190,83.3301,92.4895,0.011764707,1.0,1,0], 
[143828206,83.3301,92.4895,0.011764707,1.0,1,-1], 
[143828251,119.482666,98.4848,0.03137255,1.0,2,1], 
[143828325,123.30899,95.93237,0.027450982,1.0,2,0], 
[143828334,128.47015,92.4895,0.027450982,1.0,2,0], 
[143828351,128.47015,92.4895,0.027450982,1.0,2,-1], 
[143828406,115.19141,60.514465,0.019607844,1.0,3,1], 
[143828529,121.183105,61.51367,0.019607844,1.0,3,0], 
[143828551,121.183105,61.51367,0.019607844,1.0,3,-1], 
[143828696,105.502075,94.26935,0.023529414,1.0,8,1], 
[143828773,105.502075,94.26935,0.023529414,1.0,8,-1],
[143829030,78.24274,58.18811,0.023529414,1.0,DEL,1], 
[143829107,78.24274,58.18811,0.023529414,1.0,DEL,-1], 
[143831178,127.47159,76.28339,0.023529414,1.0,8,1],
[143831244,127.47159,76.28339,0.023529414,1.0,8,-1]]"

现在我想解析它(fromJSON())但是

德尔

在 JSON 中阻止我这样做。

请告知如何修复它。

标签: rjsondataframe

解决方案


例如,您可以用“DEL”代替 0。

json_string <- "[[143828095,86.82525,78.50037,0.011764707,1.0,1,1], [143828107,86.82525,78.50037,0.015686275,1.0,1,0], [143828174,84.82802,83.49646,0.015686275,1.0,1,0], [143828190,83.3301,92.4895,0.011764707,1.0,1,0], [143828206,83.3301,92.4895,0.011764707,1.0,1,-1], [143828251,119.482666,98.4848,0.03137255,1.0,2,1], [143828325,123.30899,95.93237,0.027450982,1.0,2,0], [143828334,128.47015,92.4895,0.027450982,1.0,2,0], [143828351,128.47015,92.4895,0.027450982,1.0,2,-1], [143828406,115.19141,60.514465,0.019607844,1.0,3,1], [143828529,121.183105,61.51367,0.019607844,1.0,3,0], [143828551,121.183105,61.51367,0.019607844,1.0,3,-1], [143828696,105.502075,94.26935,0.023529414,1.0,8,1], [143828773,105.502075,94.26935,0.023529414,1.0,8,-1], [143829030,78.24274,58.18811,0.023529414,1.0,DEL,1], [143829107,78.24274,58.18811,0.023529414,1.0,DEL,-1], [143831178,127.47159,76.28339,0.023529414,1.0,8,1], [143831244,127.47159,76.28339,0.023529414,1.0,8,-1]]"
json_string <- gsub("DEL", 0, json_string) # You can make the zero any number you like
fromJSON(json_string)

推荐阅读