Android Question Can not convert map value to Json string

junaidahmed

Well-Known Member
Licensed User
Longtime User
I am trying to convert map value to Json string ,But I am getting below error message.please check below code and advise where it is problem...

Error :-

Logger connected to: samsung SM-M325F
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
sending message to waiting queue of uninitialized activity (submitjob)
*** Receiver (httputils2service) Receive (first time) ***
true
** Activity (main) Pause event (activity is not paused). **
** Activity (listpage) Create (first time) **
** Activity (listpage) Resume **
** Activity (listpage) Pause, UserClosed = false **
** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
true
** Activity (main) Pause event (activity is not paused). **
** Activity (listpage) Create (first time) **
** Activity (listpage) Resume **
** Activity (listpage) Pause, UserClosed = false **
** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
** Activity (employeeimage) Create (first time) **
** Activity (employeeimage) Resume **
** Activity (employeeimage) Pause, UserClosed = true **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
** Activity (employeeimage) Create **
** Activity (employeeimage) Resume **
** Activity (employeeimage) Pause, UserClosed = true **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
** Service (starter) Destroy (ignored)**
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = true **
** Activity (listpage) Resume **
** Activity (listpage) Pause, UserClosed = true **
** Activity (main) Resume **
true
** Activity (main) Pause event (activity is not paused). **
true
** Activity (listpage) Create **
** Activity (listpage) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
false
** Activity (main) Pause event (activity is not paused). **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
true
** Activity (main) Pause event (activity is not paused). **
** Activity (listpage) Create (first time) **
** Activity (listpage) Resume **
** Activity (listpage) Pause, UserClosed = false **
** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **
ResponseError. Reason: , Response:
productionentry$ResumableSub_CmdSave_Clickresume (java line: 504)
org.json.JSONException: End of input at character 0 of
at org.json.JSONTokener.syntaxError(JSONTokener.java:460)
at org.json.JSONTokener.nextValue(JSONTokener.java:101)
at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:65)
at one.erp.productionentry$ResumableSub_CmdSave_Click.resume(productionentry.java:504)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8577)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
true
** Activity (main) Pause event (activity is not paused). **
** Activity (listpage) Create (first time) **
** Activity (listpage) Resume **
** Activity (listpage) Pause, UserClosed = false **
** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
** Activity (productionentry) Resume **
** Activity (productionentry) Pause, UserClosed = false **
Copying updated assets files (4)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
true
** Activity (main) Pause event (activity is not paused). **
** Activity (listpage) Create (first time) **
** Activity (listpage) Resume **
** Activity (listpage) Pause, UserClosed = false **
** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **


B4X:
Dim Body  As Map
Body   = CreateMap("jcusmid":2, "factoryid":2,"yearid":2,"jcid":2,"jcdid":2,"stage":"Fitting","process":"process 2","employeeno":536,"sam" :"2023-04-25 17:00:03.451")
Dim PostParameterS  As String = Body.As(JSON).ToString
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
I just log your code and it works fine.

B4X:
    Dim Body  As Map
    Body   = CreateMap("jcusmid":2, "factoryid":2,"yearid":2,"jcid":2,"jcdid":2,"stage":"Fitting","process":"process 2","employeeno":536,"sam" :"2023-04-25 17:00:03.451")
    Dim PostParameterS  As String = Body.As(JSON).ToString

    Log(PostParameterS)

OUTPUT
B4X:
{
    "jcdid": 2,
    "process": "process 2",
    "stage": "Fitting",
    "jcid": 2,
    "factoryid": 2,
    "jcusmid": 2,
    "employeeno": 536,
    "sam": "2023-04-25 17:00:03.451",
    "yearid": 2
}

I am seeing nextObject and nextValue. could it be that you are not processing the json response well or you are not sending the right parameters to the API?
We cant tell unless you post an example or complete code than what you posted.

You can use this tool to process your json response: https://b4x.com:51041/json/index.html
 
Upvote 0
Top