Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: DeserializeJSON: Incorrect property name in ParseObjectJson()

$
0
0
Re: DeserializeJSON: Incorrect property name in ParseObjectJson()
Web Connection 5.0
Re: DeserializeJSON: Incorrect property name in ParseObjectJson()
Jun. 3, 2013
02:58 pm
3ST0W2ALLShow this entire thread in new window
Gratar Image based on email address
From:Rick Strahl
To:Bob Roenigk
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




Rick Strahl
West Wind Technologies


from Maui, Hawaii

Making waves on the Web


Viewing all articles
Browse latest Browse all 10393

Trending Articles