Android Question JSONObject from java

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
B4X:
java.lang.ClassCastException: org.json.JSONObject cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
any help will be appreciated
 

attenzi0ne

Member
Licensed User
Hello again

This is the code:
B4X:
Dim c_worker As cls_fetcher
log(c_worker.f_get_results)
in the console this is what I see after executing that code
B4X:
(MyMap) {.section=9, signal-strength=-79}
so I assumed "f_get_results" is returning a Map and I did this:
B4X:
Dim c_worker As cls_fetcher
Dim t_map As Map = c_worker.f_get_results
but unfortunately I got this error message:
B4X:
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
 

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.

B4X:
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"))
 
Top