如何从以下响应中提取值:
{"photosets":{"cancreate":1, "page":1, "pages":1, "perpage":1, "total":1, "photoset":
[{"id":"72157629171255321", "primary":"6817523143", "secret":"250f42ed7c", "server":"7166",
"farm":8, "photos":"1", "videos":0, "title":{"_content":"Set1"}, "description":{"_content":""},
"needs_interstitial":0, "visibility_can_see_set":1, "count_views":"0", "count_comments":"0",
"can_comment":1, "date_create":"1328373127", "date_update":"1328373159"}]}, "stat":"ok"}
我需要一些不是所有的值,例如我需要“id”字段我该如何获得它?
谢谢,
答案 0 :(得分:3)
有一个非常高效的包装器(因为杰克逊......)用于scala。 杰克森会帮助你做这件事check this out。
val ids: Seq[JString] = parse[JValue]("""
{"photosets":{"cancreate":1, "page":1, "pages":1, "perpage":1, "total":1, "photoset":
[{"id":"72157629171255321", "primary":"6817523143", "secret":"250f42ed7c", "server":"7166", "farm":8, "photos":"1", "videos":0, "title":{"_content":"Set1"}, "description": {"_content":""}, "needs_interstitial":0, "visibility_can_see_set":1, "count_views":"0", "count_comments":"0", "can_comment":1, "date_create":"1328373127", "date_update":"1328373159"}]}, "stat":"ok"}
""") \\ "id"
以下是HowTo,请注意使用parse
将返回JValue
,您可以在其上调用在第一级找到的\
或\\
或之后给予任何财产的任何财产。
使用反射,Jerkson也可以在案例类中直接解析,查看文档......它非常强大
答案 1 :(得分:0)
Scala没有任何固有的内容,只需使用Jackson之类的JSON解析器并提取所需的信息。