Android Question HttpUtils2 Json API Help Me

nso91191

Member
Licensed User
Longtime User
HttpUtils2 Json Help Me Don't Get AnyData (I Get null, null, null ) :( what wrong code

Search id change but not response :(


2mzxixt.jpg
 

Attachments

  • Test.zip
    41 KB · Views: 136

nso91191

Member
Licensed User
Longtime User
not i use php, my project senior provided me json http://162.243.69.205/shipping_latest/public/api/v1/search?keyword=1

link ..

my work created a mobilewebapp ...

i don't know how to search and use api :(

===========================================
brother @NJDude SampleApp Work Fine

keyword=1 ( work fine )
keyword = blah blah blah 34235 ( work fine ( response error )
==========================================

keyword change = 2, 3, 4, 5, 6, 7, 8, 9, 10 (
{"message":"Your order still processing","status_code":200} )

not work show in app
App close .........

App ===> input search box and button click ==> show result

i need it please help me

keyword = (id) maybe whatever but show result match data

not found (id ) show error


Anyone have any examples / code snippets of this?
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I'm sorry but I don't understand what is the problem.

If you have the server that response to you with a JSON text, you need only to parse this json (with json parser library) and find out your value.

If the status_code is 200 you don't need to show the data on app.

Use B4A in debug mode, run step-by-step using F8 key, and take a look where is the problem.

I have downloaded your example but it don't works, I click on "next" button but the app don't do anything, so how can I see the problem ??

Sergio
 
Last edited:
Upvote 0

nso91191

Member
Licensed User
Longtime User
Hey @sirjo66

my problem

How to use root.get and data.get

uncomment root.get


B4X:
Sub hc_ResponseError(Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)

    Msgbox(Reason, "Error parsing")
   
End Sub

Sub ParseResults_StreamFinish(Success As Boolean, TaskId As Int)
   
    Dim jParser As JSONParser
    Dim JSONText As String
               
                JSONText = File.ReadString(File.DirDefaultExternal, "JsonData.txt")

    jParser.Initialize(JSONText)

    Dim root As Map = jparser.NextObject
    Dim data As Map = root.Get("data")
'    Dim status_code As Int = root.Get("status_code")
'    Dim message As String = root.Get("message")
   
    Dim seller_name As String = data.Get("seller_name")
    Dim shoped_date As String = data.Get("shoped_date")
    Dim arrived_date As String = data.Get("arrived_date")
    Dim error As String = data.Get("error")
    Dim next_place As String = data.Get("next_place")
    Dim customer_phone As String = data.Get("customer_phone")
    Dim seller_phone As String = data.Get("seller_phone")
    Dim customer_name As String = data.Get("customer_name")
    Dim package_name As String = data.Get("package_name")
    Dim shipping_address As String = data.Get("shipping_address")
    Dim complete As String = data.Get("complete")
    Dim passed_place As List = data.Get("passed_place")
    For Each colpassed_place As String In passed_place
    Next
    Dim error_message As String = data.Get("error_message")
    Dim quantity As String = data.Get("quantity")   

           
'                ListView1.AddSingleLine (root.Get("message"))
'                ListView1.AddSingleLine (root.Get("status_code"))
                ListView1.AddSingleLine(customer_name)
                ListView1.AddSingleLine(customer_phone)
                ListView1.AddSingleLine(shipping_address)
                ListView1.AddSingleLine(shoped_date)
                ListView1.AddSingleLine(package_name)
                ListView1.AddSingleLine(quantity)
                ListView1.AddSingleLine(seller_name)
                ListView1.AddSingleLine(seller_phone)
                ListView1.AddSingleLine(next_place)
                ListView1.AddSingleLine(arrived_date)
                ListView1.AddSingleLine(complete)
                ListView1.AddSingleLine(error)
                ListView1.AddSingleLine(error_message)
                ListView1.SetSelection(0)

End Sub


Error


B4X:
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = true **


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Resume **


Error occurred on line: 95 (main)
java.lang.RuntimeException: Object should first be initialized (Map).


    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:46)
    at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:65)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA$3.run(BA.java:319)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5142)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
    at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I think that the line with the error is
B4X:
Dim status_code As Int = root.Get("status_code")
because "status_code" exist only if ID code is not found.
Is it right ??

So, for to test if the system have found ID, you need to try to execute the line above, and catch the error
for example (not tested it):
B4X:
Dim status_code As Int = -1
Try
    status_code = root.Get("status_code")
Catch
End Try

Select Case status_code
Case 200
    ' Your order still processing
    Dim message As String = root.Get("message")
    .....  and what I need to do
Case 404
    ' Order not found
    .....  and what I need to do
Case Else
    ...... ID found
End Select
 
Last edited:
Upvote 0
Top