B4J Question java.lang.RuntimeException: JSON Array expected.

Nator

Member
Licensed User
Longtime User
Hi guys, I have the following problem when I try to consume Prestashop rest api.

and the Json answer is not complete
"total_discounts_tax_excl": "0.000000", "total_paid" ......

java.lang.RuntimeException: JSON Array expected.


B4X:
Dim j As HttpJob
    
    j.Initialize("",Me)

    j.Download("https://pasteleriastrindberg.cl/api/orders?display=full&limit=1&output_format=JSON&ws_key=secret")
    
    
    Wait For (j) JobDone(j As HttpJob)
    
    If j.Success Then
        Dim jp As JSONParser
        jp.Initialize(j.GetString2("UTF8"))
    
        Dim quotes As List = jp.NextArray
        For Each quot As Map In quotes
                
        
        Next
    
    End If
    j.Release
 

DonManfred

Expert
Licensed User
Longtime User
and the Json answer is not complete
How did you prove that? Im positive that you just used LOG which only works for text <4000
Write the result to disc to prove.

Based on your code you are expecting to get a LIST but the json only contains a MAP.

Use this tool to help you parsing the json
 
Upvote 0

Nator

Member
Licensed User
Longtime User
Dear ,
json string length is only 1560 characters,
B4X:
{"orders":[{"id":8,"id_address_delivery":"26","id_address_invoice":"26","id_cart":"30","id_currency":"2","id_lang":"2","id_customer":"12","id_carrier":"17","current_state":"5","module":"webpay","invoice_number":"0","invoice_date":"2020-06-23 13:56:03","delivery_number":"1","delivery_date":"2020-06-23 14:20:26","valid":"1","date_add":"2020-06-23 13:56:00","date_upd":"2020-06-23 14:20:27","shipping_number":"","id_shop_group":"1","id_shop":"1","secure_key":"eb9044ea790953d22863f0dcd1e63601","payment":"Webpay Plus","recyclable":"0","gift":"0","gift_message":"","mobile_theme":"0","total_discounts":"0.000000","total_discounts_tax_incl":"0.000000","total_discounts_tax_excl":"0.000000","total_paid":"11800.000000","total_paid_tax_incl":"11800.000000","total_paid_tax_excl":"11800.000000","total_paid_real":"11800.000000","total_products":"11800.000000","total_products_wt":"11800.000000","total_shipping":"0.000000","total_shipping_tax_incl":"0.000000","total_shipping_tax_excl":"0.000000","carrier_tax_rate":"0.000","total_wrapping":"0.000000","total_wrapping_tax_incl":"0.000000","total_wrapping_tax_excl":"0.000000","round_mode":"2","round_type":"2","conversion_rate":"1.000000","reference":"IMEOSDODJ","associations":{"order_rows":[{"id":"11","product_id":"39","product_attribute_id":"0","product_quantity":"1","product_name":"KUCHEN FRAMBUESA","product_reference":"","product_ean13":"","product_isbn":"","product_upc":"","product_price":"11800.000000","id_customization":"0","unit_price_tax_incl":"11800.000000","unit_price_tax_excl":"11800.000000"}]}}]}
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
the json itself contains a MAP. orders inside this map is a List.

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim orders As List = root.Get("orders")
For Each colorders As Map In orders
 Dim id_address_invoice As String = colorders.Get("id_address_invoice")
 Dim gift As String = colorders.Get("gift")
 Dim associations As Map = colorders.Get("associations")
 Dim order_rows As List = associations.Get("order_rows")
 For Each colorder_rows As Map In order_rows
  Dim unit_price_tax_excl As String = colorder_rows.Get("unit_price_tax_excl")
  Dim id_customization As String = colorder_rows.Get("id_customization")
  Dim product_upc As String = colorder_rows.Get("product_upc")
  Dim product_reference As String = colorder_rows.Get("product_reference")
  Dim product_ean13 As String = colorder_rows.Get("product_ean13")
  Dim product_price As String = colorder_rows.Get("product_price")
  Dim product_name As String = colorder_rows.Get("product_name")
  Dim product_quantity As String = colorder_rows.Get("product_quantity")
  Dim unit_price_tax_incl As String = colorder_rows.Get("unit_price_tax_incl")
  Dim product_isbn As String = colorder_rows.Get("product_isbn")
  Dim product_id As String = colorder_rows.Get("product_id")
  Dim product_attribute_id As String = colorder_rows.Get("product_attribute_id")
  Dim id As String = colorder_rows.Get("id")
 Next
 Dim total_paid_tax_excl As String = colorders.Get("total_paid_tax_excl")
 Dim total_wrapping_tax_incl As String = colorders.Get("total_wrapping_tax_incl")
 Dim recyclable As String = colorders.Get("recyclable")
 Dim id_customer As String = colorders.Get("id_customer")
 Dim round_type As String = colorders.Get("round_type")
 Dim invoice_date As String = colorders.Get("invoice_date")
 Dim carrier_tax_rate As String = colorders.Get("carrier_tax_rate")
 Dim valid As String = colorders.Get("valid")
 Dim total_discounts As String = colorders.Get("total_discounts")
 Dim reference As String = colorders.Get("reference")
 Dim id_lang As String = colorders.Get("id_lang")
 Dim mobile_theme As String = colorders.Get("mobile_theme")
 Dim total_wrapping_tax_excl As String = colorders.Get("total_wrapping_tax_excl")
 Dim total_paid As String = colorders.Get("total_paid")
 Dim total_shipping_tax_incl As String = colorders.Get("total_shipping_tax_incl")
 Dim secure_key As String = colorders.Get("secure_key")
 Dim total_products_wt As String = colorders.Get("total_products_wt")
 Dim total_shipping As String = colorders.Get("total_shipping")
 Dim id_shop As String = colorders.Get("id_shop")
 Dim delivery_number As String = colorders.Get("delivery_number")
 Dim payment As String = colorders.Get("payment")
 Dim id As Int = colorders.Get("id")
 Dim id_currency As String = colorders.Get("id_currency")
 Dim invoice_number As String = colorders.Get("invoice_number")
 Dim conversion_rate As String = colorders.Get("conversion_rate")
 Dim id_carrier As String = colorders.Get("id_carrier")
 Dim total_discounts_tax_incl As String = colorders.Get("total_discounts_tax_incl")
 Dim module As String = colorders.Get("module")
 Dim current_state As String = colorders.Get("current_state")
 Dim id_address_delivery As String = colorders.Get("id_address_delivery")
 Dim total_shipping_tax_excl As String = colorders.Get("total_shipping_tax_excl")
 Dim shipping_number As String = colorders.Get("shipping_number")
 Dim date_add As String = colorders.Get("date_add")
 Dim total_paid_real As String = colorders.Get("total_paid_real")
 Dim delivery_date As String = colorders.Get("delivery_date")
 Dim total_paid_tax_incl As String = colorders.Get("total_paid_tax_incl")
 Dim id_cart As String = colorders.Get("id_cart")
 Dim date_upd As String = colorders.Get("date_upd")
 Dim total_wrapping As String = colorders.Get("total_wrapping")
 Dim total_products As String = colorders.Get("total_products")
 Dim gift_message As String = colorders.Get("gift_message")
 Dim round_mode As String = colorders.Get("round_mode")
 Dim id_shop_group As String = colorders.Get("id_shop_group")
 Dim total_discounts_tax_excl As String = colorders.Get("total_discounts_tax_excl")
Next
 
Upvote 0

Nator

Member
Licensed User
Longtime User
thank you very much it worked perfect
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…