Break a array appart (result of swagger request) (SOLVED)

Break a array appart (result of swagger request) (SOLVED)

Postby Marc Venken » Sat May 22, 2021 1:33 pm

Afther putting a swagger command online, I get a querry result like this :

The status 200 = that there was a positive result found.

{"status":200,"data":[{"customerId":1,"gender":"","firstName":"Marc","lastName":"Venken","dob":"0000-00-00","emailAddress":"marc@maveco.be","addressBookIds":"2","defaultBillingAddressId":2,"defaultDeliveryAddressId":2,"phoneNumber":"89853445","faxNumber":"","bankAccountNumber":"","subscribedToNewsletter":"0","guestAccount":1,"approved":1,"discountGroupId":0,"discountGroupName":"","groupDiscount":"0.00","numberOfLogins":1,"lastLoginDate":"2014-09-11 10:40:15","dateCreated":"2020-04-07 21:18:10","lastModified":"2020-04-07 21:18:11"}]}

It's a array of a kind, and I dislike arrays, because they always post me trouble )))

Can someone pull it appart, so that I have the result more easy like :

Customer : 1
firstname : Marc

Or even better, in a Xbrowse.

There was a post like this, but no luck.

Code: Select all  Expand view


XBROWSER cText TITLE "HASH" NOMODAL
XBROWSER ArrayHashToArray( cText ) TITLE "ARRAY"

Static Function ArrayHashToArray( aData )

    Local aReturn  := Array( 0 )
    Local hItems   := { => }
    Local hItem    := { => }
    Local aHeaders := Array( 0 )
    Local aRow     := Array( 0 )
    Local nPositon := 0

    for each hItems in aData

        for each hItem in hItems

            if aScan( aHeaders, hItem:__enumkey) == 0

                aAdd( aHeaders, hItem:__enumkey )

            Endif

        next

    next

    aAdD( aReturn, aHeaders )

    for each hItems in aData

        aRow := Array( Len( aHeaders ) )

        for each hItem in hItems

            aRow[ aScan( aHeaders, hItem:__enumkey ) ] := hItem:__enumvalue

        next

        aAdD( aReturn, aRow )

    next

Return ( aReturn )

 
Last edited by Marc Venken on Sat May 22, 2021 1:53 pm, edited 1 time in total.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Break a array appart (result of swagger request)

Postby Marc Venken » Sat May 22, 2021 1:53 pm

The result file was a Json file. Never seen before, but found on Google

Fw can handle them... Great

I found a sample solution :

hb_JsonDecode( cText, @hHash )
XBrowse( hHash[ "data" ] )
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 118 guests