1. SHAMEEM KAKKAD
  2. PowerBuilder
  3. Tuesday, 21 February 2023 07:02 AM UTC

Hi All,

While I am taking datas from my Json.. Getting wrong result... Anybody can help ?

Jpar = create jsonparser
Jpar.LoadFile('D:\aa.txt')
rootobj_ = Jpar.GetRootItem()
data_ = Jpar.GetItemObject (rootobj_, "data")             geting result = 2
idd = Jpar.GetItemArray (data_, "sales_orders")           geting result = 3
child = Jpar.GetChildCount(idd)                                   geting result = 2
do while x_ <= child
id = Jpar.GetItemNumber (Jpar.GetChildItem(idd, x_), "id")

salesdetails = Jpar.GetChildItem (idd,x_)                     geting result = 4
saleddetailsid = Jpar.GetItemArray (salesdetails, "sales_order_details" )   geting result = 5

I don't know what is the mistake with me

Below my Json..........

{"status":true,"data":{"sales_orders":[{"id":1155,"client_id":40,"order_type":"","type":"O","order_no":"1","user_id":47,"order_status":"pending","date":"2023-02-21 00:00:00","salesman":"SHAMEER","narration":"","dod":"0000-00-00","customer_code":"13847","customer_name":"GARDEN CITY SUPERMARKET","address1":"Hedge Nagar","address2":"","latitude":"13.0389769","longitude":"77.6541024","location":"(13.0389769, 77.6541024)","invoice_path":"","device_id":"4608fce2bcce875f","cancelled_date":null,"version":1,"status":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z","sales_order_details":[{"id":5618,"sales_order_id":1155,"client_id":40,"product_code":"A0001","quantity":"1.0","price":"377.000","unit":"KG","barcode":"002365","tax_amount":"","remark":"","entry_rate":"29.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5619,"sales_order_id":1155,"client_id":40,"product_code":"A0002","quantity":"1.0","price":"377.000","unit":"KG","barcode":"002453","tax_amount":"","remark":"","entry_rate":"58.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5620,"sales_order_id":1155,"client_id":40,"product_code":"A0003","quantity":"1.0","price":"377.000","unit":"KG","barcode":"002454","tax_amount":"","remark":"","entry_rate":"116.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5621,"sales_order_id":1155,"client_id":40,"product_code":"A0004","quantity":"1.0","price":"377.000","unit":"KG","barcode":"002368","tax_amount":"","remark":"","entry_rate":"145.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5622,"sales_order_id":1155,"client_id":40,"product_code":"A0010","quantity":"1.0","price":"780.000","unit":"KG","barcode":"002811","tax_amount":"","remark":"","entry_rate":"60.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5623,"sales_order_id":1155,"client_id":40,"product_code":"A0012","quantity":"2.0","price":"780.000","unit":"KG","barcode":"002790","tax_amount":"","remark":"","entry_rate":"240.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5624,"sales_order_id":1155,"client_id":40,"product_code":"A0013","quantity":"2.0","price":"780.000","unit":"KG","barcode":"002814","tax_amount":"","remark":"","entry_rate":"300.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5625,"sales_order_id":1155,"client_id":40,"product_code":"A0017","quantity":"2.0","price":"1040.000","unit":"KG","barcode":"002430","tax_amount":"","remark":"","entry_rate":"320.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5626,"sales_order_id":1155,"client_id":40,"product_code":"A0018","quantity":"1.0","price":"1040.000","unit":"KG","barcode":"002265","tax_amount":"","remark":"","entry_rate":"400.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5627,"sales_order_id":1155,"client_id":40,"product_code":"A0021","quantity":"1.0","price":"980.000","unit":"KG","barcode":"002451","tax_amount":"","remark":"","entry_rate":"151.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5628,"sales_order_id":1155,"client_id":40,"product_code":"A0022","quantity":"2.0","price":"980.000","unit":"KG","barcode":"002364","tax_amount":"","remark":"","entry_rate":"302.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5629,"sales_order_id":1155,"client_id":40,"product_code":"A0023","quantity":"1.0","price":"980.000","unit":"KG","barcode":"002452","tax_amount":"","remark":"","entry_rate":"378.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5630,"sales_order_id":1155,"client_id":40,"product_code":"A0024","quantity":"1.0","price":"1495.000","unit":"KG","barcode":"002468","tax_amount":"","remark":"","entry_rate":"230.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5631,"sales_order_id":1155,"client_id":40,"product_code":"A0026","quantity":"1.0","price":"1495.000","unit":"KG","barcode":"002470","tax_amount":"","remark":"","entry_rate":"575.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5632,"sales_order_id":1155,"client_id":40,"product_code":"A0030","quantity":"2.0","price":"1500.000","unit":"KG","barcode":"001822","tax_amount":"","remark":"","entry_rate":"578.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5633,"sales_order_id":1155,"client_id":40,"product_code":"A0034","quantity":"1.0","price":"1287.000","unit":"KG","barcode":"002945","tax_amount":"","remark":"","entry_rate":"396.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5634,"sales_order_id":1155,"client_id":40,"product_code":"A0035","quantity":"1.0","price":"1287.000","unit":"KG","barcode":"002946","tax_amount":"","remark":"","entry_rate":"495.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5635,"sales_order_id":1155,"client_id":40,"product_code":"A0053","quantity":".5","price":"1066.000","unit":"KG","barcode":"09777","tax_amount":"","remark":"","entry_rate":"164.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5636,"sales_order_id":1155,"client_id":40,"product_code":"A0101","quantity":".5","price":"480.000","unit":"KG","barcode":"002386","tax_amount":"","remark":"","entry_rate":"20.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5637,"sales_order_id":1155,"client_id":40,"product_code":"A0102","quantity":".5","price":"480.000","unit":"KG","barcode":"002387","tax_amount":"","remark":"","entry_rate":"40.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5638,"sales_order_id":1155,"client_id":40,"product_code":"A0104","quantity":".5","price":"2280.000","unit":"KG","barcode":"09662","tax_amount":"","remark":"","entry_rate":"38.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5639,"sales_order_id":1155,"client_id":40,"product_code":"A0105","quantity":".5","price":"2280.000","unit":"KG","barcode":"09663","tax_amount":"","remark":"","entry_rate":"95.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5640,"sales_order_id":1155,"client_id":40,"product_code":"A0106","quantity":".5","price":"2280.000","unit":"KG","barcode":"09664","tax_amount":"","remark":"","entry_rate":"190.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5641,"sales_order_id":1155,"client_id":40,"product_code":"A0107","quantity":".5","price":"1080.000","unit":"KG","barcode":"002382","tax_amount":"","remark":"","entry_rate":"18.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5642,"sales_order_id":1155,"client_id":40,"product_code":"A0111","quantity":".25","price":"1440.000","unit":"KG","barcode":"002232","tax_amount":"","remark":"","entry_rate":"24.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5643,"sales_order_id":1155,"client_id":40,"product_code":"A0115","quantity":".25","price":"3240.000","unit":"KG","barcode":"09809","tax_amount":"","remark":"","entry_rate":"54.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"}]},{"id":1156,"client_id":40,"order_type":"","type":"O","order_no":"2","user_id":47,"order_status":"pending","date":"2023-02-21 00:00:00","salesman":"SHAMEER","narration":"","dod":"0000-00-00","customer_code":"14259","customer_name":"GRACE HYPERMART","address1":"narayanappa layout horamav agara","address2":"","latitude":"13.0389769","longitude":"77.6541024","location":"(13.0389769, 77.6541024)","invoice_path":"","device_id":"4608fce2bcce875f","cancelled_date":null,"version":1,"status":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z","sales_order_details":[{"id":5644,"sales_order_id":1156,"client_id":40,"product_code":"A0002","quantity":"1.0","price":"377.000","unit":"KG","barcode":"002453","tax_amount":"","remark":"","entry_rate":"58.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5645,"sales_order_id":1156,"client_id":40,"product_code":"A0003","quantity":"1.0","price":"377.000","unit":"KG","barcode":"002454","tax_amount":"","remark":"","entry_rate":"116.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5646,"sales_order_id":1156,"client_id":40,"product_code":"A0011","quantity":"1.0","price":"780.000","unit":"KG","barcode":"002812","tax_amount":"","remark":"","entry_rate":"120.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5647,"sales_order_id":1156,"client_id":40,"product_code":"A0012","quantity":"2.0","price":"780.000","unit":"KG","barcode":"002790","tax_amount":"","remark":"","entry_rate":"240.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5648,"sales_order_id":1156,"client_id":40,"product_code":"A0016","quantity":"1.0","price":"1040.000","unit":"KG","barcode":"002429","tax_amount":"","remark":"","entry_rate":"160.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5649,"sales_order_id":1156,"client_id":40,"product_code":"A0017","quantity":"1.0","price":"1040.000","unit":"KG","barcode":"002430","tax_amount":"","remark":"","entry_rate":"320.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5650,"sales_order_id":1156,"client_id":40,"product_code":"A0021","quantity":"1.0","price":"980.000","unit":"KG","barcode":"002451","tax_amount":"","remark":"","entry_rate":"151.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5651,"sales_order_id":1156,"client_id":40,"product_code":"A0022","quantity":"1.0","price":"980.000","unit":"KG","barcode":"002364","tax_amount":"","remark":"","entry_rate":"302.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5652,"sales_order_id":1156,"client_id":40,"product_code":"A0025","quantity":"1.0","price":"1495.000","unit":"KG","barcode":"002343","tax_amount":"","remark":"","entry_rate":"460.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5653,"sales_order_id":1156,"client_id":40,"product_code":"A0034","quantity":"1.0","price":"1287.000","unit":"KG","barcode":"002945","tax_amount":"","remark":"","entry_rate":"396.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5654,"sales_order_id":1156,"client_id":40,"product_code":"A0045","quantity":"1.0","price":"676.000","unit":"KG","barcode":"002378","tax_amount":"","remark":"","entry_rate":"52.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5655,"sales_order_id":1156,"client_id":40,"product_code":"A0101","quantity":".5","price":"480.000","unit":"KG","barcode":"002386","tax_amount":"","remark":"","entry_rate":"20.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5656,"sales_order_id":1156,"client_id":40,"product_code":"A0113","quantity":".25","price":"1320.000","unit":"KG","barcode":"003050","tax_amount":"","remark":"","entry_rate":"22.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"},{"id":5657,"sales_order_id":1156,"client_id":40,"product_code":"A0117","quantity":".25","price":"1020.000","unit":"KG","barcode":"003082","tax_amount":"","remark":"","entry_rate":"17.000","tax":"","status":1,"version":1,"created_at":"2023-02-21T05:27:52.000000Z","updated_at":"2023-02-21T05:27:52.000000Z"}]}],"cancelled_orders":[],"collections":[]}}

Accepted Answer
Andreas Mykonios Accepted Answer Pending Moderation
  1. Tuesday, 21 February 2023 08:32 AM UTC
  2. PowerBuilder
  3. # Permalink

Here is a modified example based on your code that would get a handle to sales_order_details and would display a messagebox with product code for each sales_order_details:

long child, rootobj_, data_, id, idd, x_, salesdetails, saleddetailsid, salesdetailschild
jsonparser Jpar

Jpar = create jsonparser
Jpar.LoadFile('c:\tests\new 23.json')
rootobj_ = Jpar.GetRootItem()
//geting result = 2
data_ = Jpar.GetItemObject (rootobj_, "data")
//geting result = 3
idd = Jpar.GetItemArray (data_, "sales_orders")
//geting result = 2
child = Jpar.GetChildCount(idd)

long ll_i, ll_sales_details_counter, ll_j
string ls_array

for ll_i = 1 to child
	salesdetails = Jpar.GetChildItem (idd, ll_i)
	saleddetailsid = Jpar.GetItemArray (salesdetails, "sales_order_details")
	
	ll_sales_details_counter = Jpar.GetChildCount(saleddetailsid)
	
	for ll_j = 1 to ll_sales_details_counter
		salesdetailschild = Jpar.getchilditem(saleddetailsid, ll_j)
		
		messagebox("", Jpar.getitemstring(salesdetailschild, "product_code"))
	next
next

if isvalid(Jpar) then destroy Jpar

Andreas.

Comment
  1. SHAMEEM KAKKAD
  2. Tuesday, 21 February 2023 08:39 AM UTC
I forget to add this line

Jpar.GetChildCount(saleddetailsid)



Thanks
  1. Helpful
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Tuesday, 21 February 2023 07:57 AM UTC
  2. PowerBuilder
  3. # 1

Hi.

What exactly you consider as wrong result? What information are you trying to obtain and cannot?

Andreas.

Comment
  1. SHAMEEM KAKKAD
  2. Tuesday, 21 February 2023 08:00 AM UTC
Actually, in sales_order_details have 26 items, but I am getting only 5
  1. Helpful
  1. Andreas Mykonios
  2. Tuesday, 21 February 2023 08:22 AM UTC
5 is a handle. Jpar.GetChildCount(saleddetailsid) would return 26...

Andreas.
  1. Helpful 1
  1. SHAMEEM KAKKAD
  2. Tuesday, 21 February 2023 08:38 AM UTC
Thanks
  1. Helpful
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Tuesday, 21 February 2023 08:23 AM UTC
  2. PowerBuilder
  3. # 2

Though I'm not sure about those results, 
analysing the given JSON @ jsoneditoronline.org, gave me few ideas...

data_ = Jpar.GetItemObject (rootobj_, "data")             geting result = 2

Root object has two objects [ status & Data ]
idd = Jpar.GetItemArray (data_, "sales_orders")           geting result = 3

data_ got three children [ sales_orders, cancelled_orders, collections ]
child = Jpar.GetChildCount(idd)                                   geting result = 2

Sales order has two children [ 0 & 1 ]

Since I have not used jsonparser directly, [instead using u_json object available in codeXchange ], I could not help you much in this area.

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.