wwJsonSerializer::DeserializeCursor

Deserializes a JSON object array result into a FoxPro cursor or table.

Cursors are serialized in JSON as object arrays, and this method converts a top level object array into a cursor by passing in the JSON and an existing writable cursor or table that is amended from the imported object data, mapping properties to fields.

This is a helper method that combines Deserialize() and CollectionToCursor().

Objects are created as new instances of EMPTY objects and passed back. Arrays are passed back as FoxPro Collection objects.

DO wwJsonSerializer

loSer = CREATEOBJECT("wwJsonSerializer")

SELECT TOP 5 * FROM Customers ORDER BY Company INTO CURSOR TQuery

CLEAR
lcJson = loSer.Serialize("cursor:TQuery", .T.)
? lcJson

USE IN TQuery && close

*** Create an empty writable cursor as 'schema' to import to
SELECT * FROM Customers WHERE 1=0 INTO CURSOR TCustomers READWRITE

*** returns 5 and TCustomers now has 5 added customers
? loSer.DeserializeCursor(lcJson, "TCustomers")

BROWSE NOWAIT

This method only works with a top level object array and does not work with child properties. The assumption is that the entire result is the table data contained in a single array.

For de-serializing child cursors in JSON, deserialize the entire object, then explicitly use CollectionToCursor() on the object properties that you want to de-serialize into a cursor.

o.DeserializeCursor(lcJson, lcReadWriteCursor)

Return Value

Number of records imported or -1 on error

Parameters

lcJson
A JSON string of an object array to be parsed.

lcReadWriteCursor
A writable cursor or table alias, which serves as the structure scheme to import the data to. Any fields matched in this cursor are imported from the json data.


See also:

Class wwJsonSerialize | wwUtils::CollectionToCursor

© West Wind Technologies, 2021 • Updated: 06/21/21
Comment or report problem with topic