0

I am making a http request to a web service using the dispatch library and scala. Everything is working fine, what I wanted to do is to convert the response into a JSON. I can already get the response but it's in a String format. Here's what I'm doing:

 val http = new Http

 val handler = http(req.as_str)

req is a Request variable containing the URL.

Thanks for the help. :D

Urist McDev
  • 498
  • 3
  • 14
jeypijeypi
  • 373
  • 1
  • 4
  • 12
  • 1
    It would be helpful if you elaborate a bit. What is a request (case class, list, map, ...)? What do you intend to do with the JSON representation? – Malte Schwerhoff Jul 04 '12 at 20:21

1 Answers1

0

If your request is a case class, you can use Lift-Json to serialise a case class tree into a json string (and back). Other such (de)serialisers exists, for exampe, sjson, but I've only worked with Lift-Json so far.

Malte Schwerhoff
  • 12,684
  • 4
  • 41
  • 71
  • In other classes, I used the scala.util.parsing.json library in creating json, will it work if I use it with dispatch? – jeypijeypi Jul 04 '12 at 15:32
  • AFAIK, ``scala.util.parsing.json`` only allows parsing JSON strings into JSON objects. Hence, you would first have to serialise a request into a string, and then deserialise it back into a JSON object. That's neither efficient nor elegant. – Malte Schwerhoff Jul 04 '12 at 20:20