1

How could I extract values from the following response:

 {"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"}

I need some values not All of them for example I need "id" field How can I get it?

Thanks,

1
  • Any solution Using lift-json, dispatch or sjson. Commented Feb 11, 2012 at 4:36

2 Answers 2

3

There is a very performant wrapper (because Jackson is...) for scala. Jerkson will help you in doing this 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"

Here is a HowTo, note the use of parse that will return a JValue, on which you can call \ or \\ that find on the first level or any the property given rigth after.

Using reflection, Jerkson is also available to parse directly in case class, check the documentation... it's very powerful

Sign up to request clarification or add additional context in comments.

Comments

0

There isn't anything inherently Scala about this, just use a JSON parser like Jackson and extract the information that you need.

1 Comment

It is not important to be part of Scala.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.