Android Question JSONObject from java

Discussion in 'Android Questions' started by attenzi0ne, Feb 28, 2015.

  1. attenzi0ne

    attenzi0ne Member Licensed User

    Hello evryone

    I have a jar that returns a JSONObject (org.json.JSONObject)
    how am I supposed to handle this return?
    I tried casting it directly into a map but I get
    Code:
    java.lang.ClassCastException: org.json.JSONObject cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
    any help will be appreciated
     
  2. DonManfred

    DonManfred Expert Licensed User

    You need provide more code i believe
    What i can see is that you are trying to use this jsonobject a a map.

    But without seeing more code it is hard to help
     
    thedesolatesoul likes this.
  3. attenzi0ne

    attenzi0ne Member Licensed User

    Hello again

    This is the code:
    Code:
    Dim c_worker As cls_fetcher
    log(c_worker.f_get_results)
    in the console this is what I see after executing that code
    Code:
    (MyMap) {.section=9, signal-strength=-79}
    so I assumed "f_get_results" is returning a Map and I did this:
    Code:
    Dim c_worker As cls_fetcher
    Dim t_map As Map = c_worker.f_get_results
    but unfortunately I got this error message:
    Code:
    java.lang.ClassCastException: org.json.JSONObject cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
    so my question is, how am I supposed to handle the java JSONObject object in b4a?

    thanks again
     
  4. Sub7

    Sub7 Active Member Licensed User

    I had similar problem, i converted it to string and the parsed in this way, not sure if this can help and if it is the best way.

    Code:
    Dim theJson As String = your jsonobject
    Dim json As JSONParser
    Dim map_01 As Map
    map_01.Initialize
    json.Initialize(theJson)
    map_01 = json.NextObject
    log(map_01.Get("fieldname"))
     
  5. DonManfred

    DonManfred Expert Licensed User

    what does cls_fetcher do?
     
    thedesolatesoul likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice