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

Re: DeserializeJSON - Arrays within Arrays

$
0
0
Re: DeserializeJSON - Arrays within Arrays
West Wind Internet Protocols
Re: DeserializeJSON - Arrays within Arrays
Feb. 24, 2013
01:36 pm
3Q20T61F8Show this entire thread in new window
Gratar Image based on email address
From:Rick Strahl
To:Roger Bradshaw
Hi Roger,

Yup that's a bug...

It took me a while to pin this down, which is why I didn't get back right away. I thought I had this fixed with a simple error, but it turns out there were a couple of fundamental parsing errors in the way I'm pulling the data out of .NET for arrays that had to get fixed.

The good news is that it's now fixed and I updated the wwClient package with the updated code. You can download the updated files from the registered site.

With that code you should now be able to reliably do:

CLEARDO wwDotnetBridgeDO wwJsonSerializer*** Nested Array lcString = "[[1,2],[3,4],[5,6]]" loSer = CREATEOBJECT("wwJsonSerializer") loArray = loSer.DeserializeJSON(lcString) ? loArray ? "Top level Array count: " + TRANSFORM(loArray.Count)*** Arrays come back as Fox CollectionsFOR EACH loChildArray IN loArray ? "Child Array size: " + TRANSFORM(loChildArray.Count)*** Each child is a Fox collectionFOR EACH loItem IN loChildArray ? loItemENDFORENDFOR*** This worked just fine before - array in object lcString = '{name: "Rick Strahl", address: { street: "32 Kaiea", phones: ["503 914-6111","808 283-7111"]} }' loSer = CREATEOBJECT("wwJsonSerializer") loCustomer= loSer.DeserializeJSON(lcString) ? loCustomer ? loCustomer.name ? loCustomer.address.street loPhones = loCustomer.address.phones ? "Phone Array Count: " + TRANSFORM(loPhones.Count)FOR EACH lcPhone IN loPhones ? lcPhoneENDFOR

Thanks for pointing this out... kind of an obsurish bug since it requires testing for nested arrays which are typically pretty rare...

+++ Rick ---


To fix change the ParseArray function header like this:

PROTECTEDFUNCTION ParseArrayJson(loObject)LOCAL loResult, loMembers, loMember, lnCount, lnX, lvValue, ; loCollection, loValue, loValues

Turns out this was a scoping error - missing locals for the collection and value were clobbering the values in these recursive calls.

+++ Rick ---


The deserializeJson function doesn't seem to handle arrays within arrays. The simple example below fails. Is this beyond the scope of the deserializer?

lcString = "[[1,2],[3,4]]"DO wwJsonSerializer && Load libsDO wwDotnetBridge loSer = CREATEOBJECT("wwJsonSerializer") loJsonResponse = loSer.DeserializeJSON(lcString)




Rick Strahl
West Wind Technologies


from Maui, Hawaii/div>
Making waves on the Web


Viewing all articles
Browse latest Browse all 10393

Trending Articles