From: | Bob Roenigk |
To: | Rick Strahl |
Should I subclass this work-around? Or are you going to leave it in your base class?
~bob
Bob,
The json object contains property names that are numbers which are not valid names in FoxPro. That's a pretty silly thing to do for any sort of object schema :-( IOW, there's no way to turn that into Fox properties as is.
However, you can modifgy this code to wwJsonSerializer:
************************************************************************ * ParseObject **************************************** *** Function: *** Assume: *** Pass: *** Return: ************************************************************************PROTECTEDFUNCTION ParseObjectJson(loObject)LOCAL loResult, loMembers, loMember, lnCount, lnX, lvValue loResult = CREATEOBJECT("EMPTY") loMembers = this.oBridge.InvokeMethod(loObject,"GetMembers") lnCount =loMembers.CountFOR lnX = 0 TO lnCount-1 loMember = loMembers.Item(lnX) lvValue = nullDOCASECASE loMember.Type = "O" lvValue = THIS.ParseObjectJson(loMember)CASE loMember.Type = "A" lvValue = THIS.ParseArrayJson(loMember)OTHERWISE lvValue = this.ParseValueJson(loMember)ENDCASE lcName = loMember.NameIFISDIGIT(LEFT(lcName,1)) lcName = "_" + lcNameENDIFADDPROPERTY(loResult,lcName,lvValue)ENDFORRETURN loResultENDFUNC
which explicitly checks for numeric values as the first character and if so prefixes it with an _ (FoxPro var names cant start with a number).
This makes it work, but you'll have to adjust your names for the numeric fields from the json to include the underscore.
+++ Rick ---
Rick,
The following code is failing on line 4 below. This is attempting to read and parse a json from a third party vendor.
oHTTP = CREATEOBJECT("wwHttp") lcHTML = oHTTP.HTTPGet("http://api.wunderground.com/api/bab473119437f545/currenthurricane/view.json","","","") loSer = CREATEOBJECT("wwJsonSerializer") loWunder = loSer.DeserializeJSON(lcHTML)
"Incorrect property name" is returned in your ParseObjectJson() function.
Using version WC v5.66 and .NET 4.5 on Win7. jsonLint.com says the json being returned in valid.
Stumped at this point.
~bob