oCustomer.Import("customers") gives an error

Aug 16, 2016 at 10:18 AM
Edited Aug 17, 2016 at 11:08 AM
There are many errors in this class:

Where is the JSON.decodeArray ?

If you use JSONArray then after Build->Rebuild Project->ERROR: Unknown object - Undefined
Why?

9 does not work, why?:

&& 9. Creating an schema instance and initializes with an external source
 SELECT Users
  LOCATE FOR id = 25
 oUser = JSONObject("schema:User", "users")
  ?oUser.id --> 25
In the PROCEDUREs import and export must be
STORE EVALUATE(puSource+"." + cProp ) TO ("THIS.Buff." + cProp)
instead of  STORE EVALUATE("puSource." + cProp) TO ("THIS.Buff." + cProp)
Why does
oCustomer.Import("customers")
give an error: PUSOURCE is not an object (Error 1924) ?:

Why paragraph 13. gives an error Property DECODEARRAY is not found (Error 1734) ?
    1. Create a JSON object and import its values from a table row:
      && JSON.declareSchema("Customer","{id:numeric,name:string,balance:numeric,active:boolean}"
      SET PROCEDURE TO qdfoxJSON ADDITIVE
      JSONStart()
      JSON.declareSchema("Customer","{CUSTid:numeric,CUSTname:string,CUSTstat:string}") && balance:numeric,active:boolean
      SELECT customers
      && LOCATE FOR id = 25
      LOCATE FOR CUSTid = "0012"
      oCustomer = JSONObject("schema:Customer")
      oCustomer.Import("customers")
      && ?oCustomer.Id && --> 25
      ?oCustomer.CUSTId && --> "0012"
Did you check all 16 examples?:
CLEAR && ekrannii tazartabiiz
! Load library:
SET PROCEDURE TO qdfoxJSON ADDITIVE
JSONStart()

&& 0. Documentation
! a. Parse a JSON string into a object:
TEXT TO cPerson NOSHOW
"fullname": "George Jetson",
"employer": "Spacely Sprockets",
"spouse": { "fullname": "Jane", "age": 20, "shopping": true },
"children": [ "Elroy", "Judy" ],
"isCool": true}
ENDTEXT

oPerson = JSON.Parse(cPerson) && Also: oPerson = JSONObject(cPerson)
?oPerson.fullName
?oPerson.Spouse.fullName
?oPerson.Children.Count
?oPerson.Children.Item[1]

! b. Serialize an object as a JSON string:*
LOCAL oCustomer
oCustomer = CREATEOBJECT("Empty")
ADDPROPERTY(oCustomer, "Id", "0001")
ADDPROPERTY(oCustomer, "fullName", "JOHN SMITH")

cCustomer = JSON.Encode(oCustomer)
?cCustomer && --> {"id":"0001", "fullName" : "JOHN SMITH

! c. Creating a JSON compatible object:
LOCAL oCustomer
oCustomer = JSONObject()
oCustomer.Add("id","0001")
oCustomer.Add("Name", "JOHN SMITH")
cCustomer = oCustomer.ToJSON()
?cCustomer

&& 1. Encoding an object to a JSON string using JSONObject (this is the preferred method):
! MESSAGEBOX(JSON.canonicalNotation)
MESSAGEBOX("a"+JSON.stringDelimitator)&& defaultii: '
&& JSON.stringDelimitator = ["] && Uzgartabez' kirak' bulsa " ga
 myObject = JSONObject()
 myObject.add("Name","foo")
 myObject.add("Age",40)
 jsonString = myObject.ToJSON()
 ?jsonString && "{name:'foo', age:40}"
&& 2. Encoding an object to a JSON string:
 myObject = CREATEOBJECT("Empty")
 ADDPROPERTY(myObject,"Name","foo")
 ADDPROPERTY(myObject,"Age",40)
 jsonString = JSON.Encode(myObject)
 ?jsonString 
    1. Parsing a JSON string using JSONObject (this is the preferred method):
      myObject = JSONObject(jsonString)
    1. Parsing a JSON string using Parse() method:
      myObject = JSON.Parse(jsonString)
    1. Creating a JSONObject manually:
      myObject = JSONObject("{name:'Foo',age:40}")
      ?myObject.Name && --> 'Foo'
      ?myObject.Age && --> 40
      myObject.Add("Sex","Male")
      ?myObject.Sex && --> 'Male'
      && SET STEP ON
      && myObject.addArray("Hobbies","['Read','Trekking','Football']")
      myObject.addArray("Hobbies","'Read','Trekking','Football'") && OST && ostagesenda' shakmak yabkiichlar artiik
      ?myObject.Hobbies.Count && --> 3
      ?myObject.Hobbies[2] && --> 'Trekking' && Doesn't work in VFP6
      ?myObject.Hobbies.Item[2] && --> 'Trekking' && Will work in all versions
    myObject.Add("Car","{Maker:'Hyundai',Model:'Accent',Year:2007}")
    ?myObject.Car.Maker && --> "Hyundai"
    myObject.Car.Add("Engine","V4 1.3 lts")
    ?myObject.Car.Engine && --> 'V4 1.3 lts'
    1. Creating a JSONObject from a declared schema: [1]
      JSON.declareSchema("User",;
      "{loginName:string,"+;
      " fullName:string,"+;
      " password:string,"+;
      " lastLogin:datetime}")
      myObject = JSONObject("schema:User")
      ?myObject.Schema && --> User
      myObject.loginName = "vespina"
    1. Create a JSON object and import its values from a table row:
      && JSON.declareSchema("Customer","{id:numeric,name:string,balance:numeric,active:boolean}"
      SET PROCEDURE TO qdfoxJSON ADDITIVE
      JSONStart()
      JSON.declareSchema("Customer","{CUSTid:numeric,CUSTname:string,CUSTstat:string}") && balance:numeric,active:boolean
      SET STEP ON
      SELECT customers
      && LOCATE FOR id = 25
      LOCATE FOR CUSTid = "0012"
      oCustomer = JSONObject("schema:Customer")
      oCustomer.Import("customers")
      && ?oCustomer.Id && --> 25
      ?oCustomer.CUSTId && --> "0012"
    1. Update a data record from a JSON object:
      oCustomer = JSONObject("schema:Customer")
      oCUstomer.Id = 25
      oCUstomer.Name = "VICTOR ESPINA"
      oCustomer.Balance = 1244.23
      oCustomer.Active = .T.
      SELECT customers
      APPEND BLANK
      oCustomer.Export("customers")
      ?id && --> 25
      ?name && --> 'VICTOR ESPINA'
    1. Creating an schema instance and initializes with an external source
      SELECT Users
      LOCATE FOR id = 25
      oUser = JSONObject("schema:User", "users")
      ?oUser.id && --> 25
    1. Encode a data cursor: [2]
      cCursorData = JSON.encodeCursor("QDATA")
      USE IN QDATA
    1. Restore a data cursor from JSON string:
      JSON.parseCursor(cCursorData)
      SELECT QDATA
    1. Convert an array in a JSON-friendly object:
      object = JSONArray(@array)
    1. Create a JSON-friendly array object from a JSON string:
      object = JSONArray("['Red','Yellow','Green']")
      ?object[1] && --> 'Red'
    1. Use a JSON array object to get a JSON representation of an array:
      object = JSONArray(@array)
      cJSON = object.ToJSON()
    1. Export the contents of a JSON array object to a VFP array:
      LOCAL ARRAY myArray[1]
      object = JSONArray("['Red','Yellow','Green']")
      object.ToArray(@myArray) ?myArray[1] && --> 'Red'
    1. Parsing the result of a URL call in JSON format:
      object = JSONObject("url:http://weather.yahooapis.com/forecastjson?w=2502265")