R中的JSON格式拒绝解析?

时间:2018-07-26 11:48:38

标签: r json dataframe

这是我的玩具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()

  

DEL

JSON中的

阻止我执行此操作。

请告知如何解决。

2 个答案:

答案 0 :(得分:1)

您可以将“ 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)

答案 1 :(得分:0)

使用json解析器(http://json.parser.online.fr/),只需在相应位置删除“ DEL”似乎可以解决此问题。