On Tue, Oct 27, 2009 at 10:02 AM, GA <[email protected]> wrote:

> Thanks David.
>
> It works with a little change.
>
> I cannot do parse(new String(req.body, "UTF-8")) directly, because the type
> of req.body is net.liftweb.util.Box[Array[Byte]]. So I did this:
>
>         var message = ""
>         for (i <- req.body) {
>             message = new String(i, "UTF-8")
>         }
>         val json = parse(message)
>

val json = parse(req.body.map(bytes => new String(bytes, "UTF-8")) openOr
"")



>
> Is there an easier way to write this? I am quite new in scala yet.
>
> Thanks,
>
> GA
>
>
>
> On Oct 27, 2009, at 5:09 PM, David Pollak wrote:
>
>
>
> On Tue, Oct 27, 2009 at 9:05 AM, GA <[email protected]> wrote:
>
>>
>> Hello guys,
>>
>> I have a small Lift API that has to receive JSON content. The content-
>> type is specified as "application/json". The API method is written as
>> follows:
>>
>>     def jsonTest(req: Req): LiftResponse = {
>>
>>         implicit val formats = net.liftweb.json.DefaultFormats //
>> Brings in default date formats etc.
>>         case class Person(name: String, password: String)
>>         val json = parse(req.body.toString) /* Line that fails */
>>         val person = json.extract[Person]
>>         CreatedResponse(wrapXmlBody(<operation id="jsonTest"
>> success="true"> </operation>), "application/json")
>>     }
>>
>>
>> I want to parse the content using the net.liftweb.jsonParser but the
>> server returns HTTP 500 error.
>>
>
> req.body is an Array[Byte].  calling .toString on it will not yield a
> String representing the Array[Byte].
>
> Try parse(new String(req.body, "UTF-8"))
>
> If this doesn't work, please include the stack trace.
>
>
>>
>> If the content-type is text/xml, the message comes inside of req.xml,
>> where does it come when it is application/json?
>>
>> Thanks in advance,
>>
>> GA
>>
>>
>>
>>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Surf the harmonics
>
>
>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to