Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem: "Extracting" JSON using lift-json in an Android (Scala) application
    primarykey
    data
    text
    <p>I want to deserialize a JSON-String using the lift-json library. In my Android application I'm using Scala 2.9.0 and lift-json_2.9.0_2.4-M1.</p> <p>I took a simple example from lift-json readme, but everytime I try to extract values from the JSON-String I get a net.liftweb.json.MappingException when calling the Activity. It seems there are no args delivered to "extract".</p> <p>Here is my Activity:</p> <pre><code>import _root_.android.app.Activity import _root_.android.os.Bundle import net.liftweb.json._ class JsonTest extends Activity { override def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) setContentView(R.layout.mainactivity) implicit val formats = DefaultFormats case class NumList(numbers: List[Int]) val json = parse(""" { "numbers" : [1, 2, 3, 4] } """) json.extract[NumList] } } </code></pre> <p>and here the exception I get:</p> <pre><code>06-29 12:09:31.548: ERROR/AndroidRuntime(405): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{de.fhs.spirit/de.fhs.spirit.JsonTest}: net.liftweb.json.MappingException: Parsed JSON values do not match with class constructor args= arg types= constructor=public de.fhs.spirit.JsonTest$NumList$2(de.fhs.spirit.JsonTest,scala.collection.immutable.List) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at android.app.ActivityThread.access$2300(ActivityThread.java:125) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method) Caused by: net.liftweb.json.MappingException: Parsed JSON values do not match with class constructor args= arg types= constructor=public de.fhs.spirit.JsonTest$NumList$2(de.fhs.spirit.JsonTest,scala.collection.immutable.List) at net.liftweb.json.Meta$.fail(Meta.scala:185) at net.liftweb.json.Extraction$.instantiate$1(Extraction.scala:257) at net.liftweb.json.Extraction$.newInstance$1(Extraction.scala:280) at net.liftweb.json.Extraction$.build$1(Extraction.scala:298) at net.liftweb.json.Extraction$.extract0(Extraction.scala:345) at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$extract0(Extraction.scala:194) at net.liftweb.json.Extraction$.extract(Extraction.scala:42) at net.liftweb.json.JsonAST$JValue.extract(JsonAST.scala:290) at de.fhs.spirit.JsonTest.onCreate(JsonTest.scala:16) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 more </code></pre> <p>Would be great if you have an idea how to solve my problem. Thank you!</p> <p>Greetings, Illaz</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload