Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: wwJsonSerializer

$
0
0
Re: wwJsonSerializer
Web Connection 5.0
Re: wwJsonSerializer
May. 6, 2013
02:41 am
3S105RGC2Show this entire thread in new window
Gratar Image based on email address
From:Rick Strahl
To:Rodney Eales

Ah yes. The original implementations didn't properly manage child arrays, so it sounds like you were in fact running the original code...

Glad it's working - you had me worried there for a minunte until I double checked...

+++ Rick ---


Hi Rick

Problem sorted. I could not work it out why you were not getting the same results as I did.

Recompiled classlibs etc and all good.

Thanks for looking at it.

Yes I ran your code and it all failed because it referenced the wrong items. The snippet I posted worked once I changed that bit of code. The next bit of code failed as it should...

+++ Rick ---



Hi Rick

Did you run my code ?

I agree that register_sale_products[2] should not exist but it does. The code does not fail in this example. It only fails when demonstrating the 3rd issue.

Tks
Rodney


Just taking a quick looks: your logic in retrieving the values is wrong.

I'm not clear when you say that the product collection item shouldn't exist - of course it should it's there in the JSON. The problem with the first code is that there is no value property on the product, it's on the product's attributes. You need to drill into the attributes and this works fine returning the proper values of line_note and empty.

loProduct = loCust2.register_sales[1].register_sale_products[1] ? loProduct.Attributes[1].Name ? loProduct.Attributes[1].Value

The next block of code references an element that doesn't exist (register_sale_products[2]) and rightly that code fails.
Same thing with the next block code.

I stopped at this point, because it seems you're looking at something different than what's actually running there.

+++ Rick


Hi Rick

Hope this demonstrates

DO wwJsonSerializer && Load libsDO wwDotNetBridge loSer = CREATEOBJECT("wwJsonSerializer")TEXTTO lcJson NOSHOW {"register_sales": [ { "id": "c4e35708", "customer_id": "cc52b3f3", "customer_name": "Test1", "customer": { "id": "cc52b3f3", "name": "Test1", "contact": {} }, "register_sale_products": [ { "sku": "coffee-hot", "name": "Coffee (Demo)", "quantity": 1, "attributes": [ { "name": "line_note", "value": "" } ] } ],"totals": {"total_tax": 0.37,"total_price": 2.63 },"register_sale_payments": [] } ] }ENDTEXTCLEAR loCust2 = loSer.DeserializeJson(lcJson) *----------------------- 1st problem --------------------------- ? '1st Problem' ? '----- This collection element of register_sale_products[] should not exist ----' ? 'loCust2.register_sales[1].register_sale_products[1].name='+loCust2.register_sales[1].register_sale_products[1].name ? 'loCust2.register_sales[1].register_sale_products[1].value='+loCust2.register_sales[1].register_sale_products[1].value ? '----- Correct below but should be the 1st element of register_sale_products[] ----' ? 'loCust2.register_sales[1].register_sale_products[2].name='+loCust2.register_sales[1].register_sale_products[2].name ? 'loCust2.register_sales[1].register_sale_products[2].Sku='+loCust2.register_sales[1].register_sale_products[2].Sku ? 'loCust2.register_sales[1].register_sale_products[2].Attributes[1].name='+loCust2.register_sales[1].register_sale_products[2].Attributes[1].name ? 'loCust2.register_sales[1].register_sale_products[2].Attributes[1].value='+loCust2.register_sales[1].register_sale_products[2].Attributes[1].value ? *----------------------- 2nd problem --------------------------- ? '2nd Problem - This collection should be Empty register_sale_payments": []" ' ? 'loCust2.register_sales[1].register_sale_payments[1].customer.name='+loCust2.register_sales[1].register_sale_payments[1].customer.name ? *----------------------- 3rd problem --------------------------- ? '3rd Problem If you have 2 record sets in the Jason it crashes.'TEXTTO lcJson NOSHOW {"register_sales": [ { "id": "c4e35708", "customer_id": "cc52b3f3", "customer_name": "Test1", "customer": { "id": "cc52b3f3", "name": "Test1", "contact": {} }, "register_sale_products": [ { "sku": "coffee-hot", "name": "Coffee (Demo)", "quantity": 1, "attributes": [ { "name": "line_note", "value": "" } ] } ],"totals": {"total_tax": 0.37,"total_price": 2.63 },"register_sale_payments": [] }, {"id": "c4e35709","customer_id": "cc52b3f4","customer_name": "Test2","customer": {"id": "cc52b3f4","name": "Test2","contact": {} },"register_sale_products": [ { "sku": "coffee-cold", "name": "Coffee Cold (Demo)", "quantity": 1, "attributes": [ { "name": "line_note", "value": "" } ] } ],"totals": {"total_tax": 2.37,"total_price": 10.63 },"register_sale_payments": [ { "name": "Cash", "amount": -2.05 }, { "name": "Card", "amount": -10.05 } ] } ] }ENDTEXT loCust2 = loSer.DeserializeJson(lcJson)


Please post some code for each of those points that demonstrates. I don't want to wade though your hierarchy.

Please use the code markup features here in the forum.

Thanks,

+++ Rick ---



Hi

I am having some issues using DeserializeJson as follows:

1. An embedded array creates a new element in the array (collection) above it and not as a collection in its own level. (bit confusing) See 'Attributes' in example below. It creates 2 elements in register_sale_products, 1 which just has the attribute element's values and a second which is correct.

2. An empty array [] creates an object with the parent's elements. See 'Register_sale_payments' (1st record set) in example.

3. If there is more than one record set in the Json, PassArrayJson gives you a loValue is not an object.

To test points 1 and 2 you will need to remove the second record set from the example below.


Any advise please.

Many Thanks
Rodney


{ "register_sales": [ { "id": "c4e35708", "customer_id": "cc52b3f3", "customer_name": "Test1", "customer": { "id": "cc52b3f3", "name": "Test1", "contact": {} }, "register_sale_products": [ { "sku": "coffee-hot", "name": "Coffee (Demo)", "quantity": 1, "attributes": [ { "name": "line_note", "value": "" } ] } ], "totals": { "total_tax": 0.37, "total_price": 2.63 }, "register_sale_payments": [] }, { "id": "c4e35709", "customer_id": "cc52b3f4", "customer_name": "Test2", "customer": { "id": "cc52b3f4", "name": "Test2", "contact": {} }, "register_sale_products": [ { "sku": "coffee-cold", "name": "Coffee Cold (Demo)", "quantity": 1, "attributes": [ { "name": "line_note", "value": "" } ] } ], "totals": { "total_tax": 2.37, "total_price": 10.63 }, "register_sale_payments": [ { "name": "Cash", "amount": -2.05 }, { "name": "Card", "amount": -10.05 } ] } ] }










Rick Strahl
West Wind Technologies


from Maui, Hawaii

Making waves on the Web


Viewing all articles
Browse latest Browse all 10393

Trending Articles