Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert json to cursor
Message
De
31/10/2019 08:07:21
 
 
À
31/10/2019 07:44:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Applications Internet
Divers
Thread ID:
01671750
Message ID:
01671751
Vues:
58
>File contains invoice list in json format like:
>
>
{
>    "status": "OK", "statusCode": 200, "messages": null,
>    "data": [{
>        "payment_type": "banktransfer", "fine": "0.200000", "quote_id": null, "order_id": null, "prepayment_id": null, "credited_invoices": [],
>        "interested_party_address_id": 279, "project_id": 875, "currency": "EUR", "owner_id": 3, "date": "2019-03-15", "deadline": "2019-03-20",
>    },
>
>
>    {
>        "payment_type": "banktransfer", "fine": "0.30000", "quote_id": null, "order_id": null, "prepayment_id": null, "credited_invoices": [],
>        "interested_party_address_id": 79, "project_id": 85, "currency": "EUR", "owner_id": 3, "date": "2019-04-15", "deadline": "2019-43-20",
>    }
>    .... more same type elements
>    ]
>}
>
>How to convert it to FoxPro cursor ?
>Cursor sould contain payment_type, fine, quote_id etc columns.
>
>I tried
>
>https://archive.codeplex.com/?p=qdfoxjson
>
>and
>
>http://www.sweetpotatosoftware.com/blog/index.php/2008/12/19/visual-foxpro-json-class-update/
>
>but it looks like they require json to be in different format than my json.
>
>Posted also in https://stackoverflow.com/questions/58642818/how-to-convert-json-to-foxpro-cursor

I don't know what the whole file format is, but this is a way to extract the data if it's in the general form like the TEXT..ENDTEXT portion:
TEXT TO lcJson NOSHOW
{
    "status": "OK", "statusCode": 200, "messages": null,
    "data": [{
        "payment_type": "banktransfer", "fine": "0.200000", "quote_id": null, "order_id": null, "prepayment_id": null, "credited_invoices": [],
        "interested_party_address_id": 279, "project_id": 875, "currency": "EUR", "owner_id": 3, "date": "2019-03-15", "deadline": "2019-03-20",
    },
    {
        "payment_type": "banktransfer", "fine": "0.30000", "quote_id": null, "order_id": null, "prepayment_id": null, "credited_invoices": [],
        "interested_party_address_id": 79, "project_id": 85, "currency": "EUR", "owner_id": 3, "date": "2019-04-15", "deadline": "2019-43-20",
    }]
}
ENDTEXT

CLEAR

lcBody   = STREXTRACT(lcJson, "[{", "}]")
lcHeader = ALLTRIM(CHRTRAN(STRTRAN(lcJson, lcBody, SPACE(0)), "{}[]" + CHR(13) + CHR(10), SPACE(0)))
lcHeader = ALLTRIM(CHRTRAN(lcHeader, CHR(13) + CHR(10), SPACE(0)))
lcBody   = "{" + ALLTRIM(CHRTRAN(lcBody, CHR(13) + CHR(10), SPACE(0))) + "}"
*? lcHeader
*? "-----"
*? lcBody
*? "-----"

* Show header fields
lnCount = GETWORDCOUNT(lcHeader, ",")
FOR lnI = 1 TO lnCount
    lcCombo = ALLTRIM(GETWORDNUM(lcHeader, lnI, ","))
    lcField = ALLTRIM(CHRTRAN(GETWORDNUM(lcCombo, 1, ":"), CHR(34), SPACE(0)))
    lcData  = ALLTRIM(CHRTRAN(GETWORDNUM(lcCombo, 2, ":"), CHR(34), SPACE(0)))
    IF lcField != "data"
        ? lcField + " ---> " + lcData
    ENDIF
NEXT

* Show body records
? "-----"
FOR lnRecord = 1 TO 9999999
    * Grab the whole record
    lcRecord = STREXTRACT(lcBody, "{", "}", lnRecord)
    IF EMPTY(lcRecord)
        EXIT
    ENDIF

    * Display each sub-field
    lnCount = GETWORDCOUNT(lcRecord, ",")
    FOR lnI = 1 TO lnCount
        lcCombo = ALLTRIM(GETWORDNUM(lcRecord, lnI, ","))
        lcField = ALLTRIM(CHRTRAN(GETWORDNUM(lcCombo, 1, ":"), CHR(34), SPACE(0)))
        lcData  = ALLTRIM(CHRTRAN(GETWORDNUM(lcCombo, 2, ":"), CHR(34), SPACE(0)))
        IF NOT EMPTY(lcField)
            ? lcField + " ---> " + lcData
        ENDIF
    NEXT
    ? "-----"
NEXT
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform