If you absolutely can't live with the data being serialized as an object with Count and Rows properties, you will have to use an alternative method to create the output.
One option is to transform your data to an array of objects. Each object will have properties corresponding to your data fields). You can then use fwJSON.Write to export your array.
Another possibility would be to use regular expressions and string manipulation to alter the json string after it is generated.
Finally, if you don't want the field names in your serialized string, you can use COPY TO ARRAY to first export your data to an array. In this case, the output will be an array of arrays, where the outer array will contain the rows, while the inner arrays will represent individual records.
FoxWeb Support Team
Sent by irace_z28 on 10/11/2012 09:02:11 AM:
Thanks for clearing that up.
I am using the fwSON.Write method but after reading your response, I realized why am I getting the rows and count properties...I have my object created with fwCursor class which is identical to the output that the fwJSON.WriteCursor method and that is what I overlooked.
SELECT * FROM aTable INTO CURSOR aCursor
IF RECCOUNT() > 0
* Set the content type to text/plain to prevent some Ajax frameworks from complaining
Response.ContentType = "text/plain"
fwJSON.Beautify = .T.
JSONResponse = CREATEOBJECT("CUSTOM")
JSONResponse.aaData = CREATEOBJECT("fwCursor", "aCursor")
aString = fwJSON.Write(JSONResponse)
In any case, the output from above is what I need but without the rows and count properties.
Unfortunately,the ExcludedProperties would not work in my situation and being new to JSON, I'm having a hard time figuring this out.
Sent by FoxWeb Support on 10/10/2012 06:11:54 PM:
Are you sure you are using fwJSON.Write? The fwJSON.WriteCursor method adds a Rows and Count properties, but the Write method only outputs existing properties of the objects being serialized (minus the default VFP properties listed in the documentation).
The documentation for ExcludedProperties seems clear enough to me:
property contains a comma-separated list of object properties that are omitted from JSON strings, produced by the Write
method. If the object being serialized is based on the VFP's Custom class, then the following properties are omitted by default, so there is no need to include them in ExcludedProperties
: Application, BaseClass, Class, ClassLibrary, Comment, ControlCount, Controls, Height, HelpContextId, Left, Name, Objects, Parent, ParentClass, Picture, Tag, Top, WhatsThisHelpId, Width. This property is read/write.
Let's say for example that you were serializing an object containing Rows and Count properties. If you wanted to omit these from the JSON string, you would use the following:
fwJSON.ExcludedProperties = "rows,count"
M.JsonString = fwJSON.Write(M.MyObject)
Note that ExcludedProperties does not affect the WriteCursor method.
FoxWeb Support Team
Sent by irace_z28 on 10/10/2012 05:02:00 PM:
I have a JSON string that throws in the properties "count" and "rows" by default using the jwJSON.Write method.
How do I remove those properties?
I looked at the "ExcludedProperties" but the description didn't help and there are no examples.