tufanv Expert Licensed User Longtime User Jun 27, 2018 #1 Hello, My app is working on a requesting data from a webserver with http request and return json as response. Some crash reports show this error : Exception java.lang.RuntimeException: JSON Object expected. anywheresoftware.b4a.objects.collections.JSONParser.NextObject (JSONParser.java:50) ct.canlidoviz.main._jobdone (main.java:1311) Click to expand... Line that is equal to main.java 1311 is : Code: Copy If Job.JobName="songrafik" Then If Job.Success = True Then Log(Job.GetString) Dim parser As JSONParser parser.Initialize(Job.GetString) As I can understand from the percentage of error ( it is around %5 of all users ) most of the time there is no problem , but I want to fix this. If the job is success , I must have get the json also because it is impossible to get a blank response from the server. This error happens when the received response is not json so to fix this , Can I use for example try catch for the above code and if stg is catched repeat this job ? TY
Hello, My app is working on a requesting data from a webserver with http request and return json as response. Some crash reports show this error : Exception java.lang.RuntimeException: JSON Object expected. anywheresoftware.b4a.objects.collections.JSONParser.NextObject (JSONParser.java:50) ct.canlidoviz.main._jobdone (main.java:1311) Click to expand... Line that is equal to main.java 1311 is : Code: Copy If Job.JobName="songrafik" Then If Job.Success = True Then Log(Job.GetString) Dim parser As JSONParser parser.Initialize(Job.GetString) As I can understand from the percentage of error ( it is around %5 of all users ) most of the time there is no problem , but I want to fix this. If the job is success , I must have get the json also because it is impossible to get a blank response from the server. This error happens when the received response is not json so to fix this , Can I use for example try catch for the above code and if stg is catched repeat this job ? TY
DonManfred Expert Licensed User Longtime User Jun 27, 2018 #2 What about checking the length of the result before using jsonparser???? What is the result when it fails? what do you get with your Code: Copy Log(Job.GetString) ? Upvote 0
What about checking the length of the result before using jsonparser???? What is the result when it fails? what do you get with your Code: Copy Log(Job.GetString) ?
tufanv Expert Licensed User Longtime User Jun 27, 2018 #3 DonManfred said: What about checking the length of the result before using jsonparser???? What is the result when it fails? what do you get with your Code: Copy Log(Job.GetString) ? Click to expand... I normally get stg like this : Code: Copy {"status":true,"data":[{"value":"4.62195","date":"2018-06-27 05:49:59"},{"value":"4.62095","date":"2018-06-27 06:22:58"},{"value":"4.62245","date":"2018-06-27 06:55:58"},{"value":"4.62275","date":"2018-06-27 07:28:59"},...... Yes , I was thinking that , if i check if the job.getstring.length is less then 10 for example , and if it is less than 10 repeat the job request , I would fix the problem, it is better than try catch .. Upvote 0
DonManfred said: What about checking the length of the result before using jsonparser???? What is the result when it fails? what do you get with your Code: Copy Log(Job.GetString) ? Click to expand... I normally get stg like this : Code: Copy {"status":true,"data":[{"value":"4.62195","date":"2018-06-27 05:49:59"},{"value":"4.62095","date":"2018-06-27 06:22:58"},{"value":"4.62245","date":"2018-06-27 06:55:58"},{"value":"4.62275","date":"2018-06-27 07:28:59"},...... Yes , I was thinking that , if i check if the job.getstring.length is less then 10 for example , and if it is less than 10 repeat the job request , I would fix the problem, it is better than try catch ..
DonManfred Expert Licensed User Longtime User Jun 27, 2018 #4 tufanv said: I normally get stg like this Click to expand... but in case of the error it seems to be something other.. Upvote 0
tufanv said: I normally get stg like this Click to expand... but in case of the error it seems to be something other..
tufanv Expert Licensed User Longtime User Jun 27, 2018 #5 DonManfred said: but in case of the error it seems to be something other.. Click to expand... I assume that it returns an empty string or null, so if there was a , isJson check it would be good Upvote 0
DonManfred said: but in case of the error it seems to be something other.. Click to expand... I assume that it returns an empty string or null, so if there was a , isJson check it would be good
Pendrush Well-Known Member Licensed User Longtime User Jun 27, 2018 #6 I have similar situation with JSON, use Try Catch to catch error. Upvote 0
OliverA Expert Licensed User Longtime User Jun 27, 2018 #7 tufanv said: Can I use for example try catch for the above code and if stg is catched repeat this job ? Click to expand... With Wait For, that could be easier implemented than using JobDone. Code: Copy ' Do While retry = True Dim j As HttpJob j.Initialize("", Me) j.Download("https://www.google.com") Wait For (j) JobDone(j As HttpJob) If j.Success Then Log(j.GetString) Dim parser As JSONParser Try parser.Initialize(j.GetString) retry = False Catch Log(LastException) End Try End If j.Release Loop Note: Just noticed that this will repeat constantly if j.Success is False. That may or not may not be the intended purpose and the code may need to be adjusted. Plus, you don't have to use try/catch (should have read follow up posts better), but then this can be adapted to whatever is used to determine if the returned value (j.GetString) is acceptable. Last edited: Jun 27, 2018 Upvote 0
tufanv said: Can I use for example try catch for the above code and if stg is catched repeat this job ? Click to expand... With Wait For, that could be easier implemented than using JobDone. Code: Copy ' Do While retry = True Dim j As HttpJob j.Initialize("", Me) j.Download("https://www.google.com") Wait For (j) JobDone(j As HttpJob) If j.Success Then Log(j.GetString) Dim parser As JSONParser Try parser.Initialize(j.GetString) retry = False Catch Log(LastException) End Try End If j.Release Loop Note: Just noticed that this will repeat constantly if j.Success is False. That may or not may not be the intended purpose and the code may need to be adjusted. Plus, you don't have to use try/catch (should have read follow up posts better), but then this can be adapted to whatever is used to determine if the returned value (j.GetString) is acceptable.