Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strings maintaining leading and trailing quotes from JSON when using Jerkson

JSON in question:

{
"search_id": "",
"type": "Search.filter",
"query": "bar,club",
"params": {
    "search_id": "",
    "user_id": "",
    "client": "ios",
    "lat": 40.73199375351,
    "lon": -74.00080404533901,
    "radius": 20
}

}

Code to Retrieve the Data:

val json = Json.parse(new String(body))
println((json \ "search_id") + " | " + (json \ "query"))
println(json)

printing just the json JsValue prints out the entire JSON as expected. printing out the first item produces: "" | "bar,club"

Why is it maintaining the quotes from JSON formatting? That's not part of the string, it's basically saying that the content inside the quotes is a string. How do I fix this?

like image 440
Commander Avatar asked Mar 22 '13 20:03

Commander


1 Answers

According to the doc, you should call .as[sometype] (unsafe conversion) or asOpt[sometype] (safe).

println((json \ "search_id").as[String] + " | " + (json \ "query").as[String])
like image 117
Alex Yarmula Avatar answered Oct 20 '22 16:10

Alex Yarmula