解析json时,由于输入结束,没有要映射的内容 [英] No content to map due to end-of-input when parsing json

查看:462
本文介绍了解析json时,由于输入结束,没有要映射的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用play JSON库工具解析Spark中的JSON数据,并收到以下错误消息.有人对导致此错误的原因有任何线索吗?如果这是由于错误的JSON记录引起的,那么如何识别错误的记录呢?谢谢!

I was using the play JSON library tools to parse a JSON data in Spark, and got the following error message. Does anyone have any clue about possible cause of this error? If this is due to a bad JSON record, how can I identify the bad record? Thanks!

这是我用来解析JSON数据的主要脚本:

Here is the major script I used to parse the JSON data:

import play.api.libs.json._
val jsonData = distdata.map(line => Json.parse(line)) //line 194 of script parseJson_v14.scala
val filteredData = jsonData.map(json => (json \ "QueryStringParameters" \ "pr").asOpt[String].orNull).countByValue()

变量distdata是文本格式JSON数据的rdd,变量jsonData是JsValue数据的rdd.由于Spark转换是惰性的,因此直到执行第二条命令来创建变量filteredData时错误才跳出来,并且根据错误消息,错误来自于我创建变量jsonData的第一条命令.

Variable distdata is a rdd of text format JSON data, variable jsonData is a rdd of JsValue data. Since Spark transformation is lazy, the error didn't jump out until the 2nd command is executed to create the variable filteredData, and according to the error message, the error comes from the the 1st command where I create the variable jsonData.

推荐答案

检查distdata中是否没有空行,并且一行中是否包含所有JSON对象,例如

Check if you have no blank lines in distdata and that you have all JSON object in one line, like

{"id":"121", "name":"robot 1"}
{"id":"122", "name":"robot 2"}

{"id":"121", "name":
"robot 1"}
{"id":"122", "name":
"robot 2"}

这篇关于解析json时,由于输入结束,没有要映射的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆