Json cursor parsing

Oct 15, 2013 at 6:18 PM
Why can't I parse the serialized cursors ?
SearchResults is a cursor. Serialize it.
aa = oJSON.stringify("SearchResults")

Now try making cursor out of this 'aa' json object. I expect a table named (bb) to be created.
bb = oJSON.parse(aa)

No table gets created and ?USED(bb) command returns an error message.
Oct 17, 2013 at 2:12 AM

Is this for version 603? I experienced a bug in version 553 which forced me to add another prg called JSON2.PRG. There was a thread on this issue:

Which summarize the things that I discovered:
I have found the obvious since I was using version aVFP 5.XX. The jSON implementation included in this version that I have seems buggy. When I added the latest version from Craig's into my project, it worked like a charm. I will try to post some sample code on this thread once I completed my work.

I cannot comment of 603 since I'm just beginning to use it and founding things that makes me pull my hair again. :)
Oct 17, 2013 at 4:29 AM
thanks for the heads-up apaustria. I'll re-try after loading Craig's latest release.
Oct 17, 2013 at 10:36 PM
Edited Oct 17, 2013 at 10:48 PM
Hi apaustria,

Did you manage to get ajax POST working in AVFP? I am sending serialized Json to server, but I cannot find it in oRequest.forms. Any idea's from where I can flush it out?
BTW, I trying to use RESTful module for processing this data.


If you have any link to Jquery mobile on this topic.. it would help me a lot.
Oct 17, 2013 at 11:29 PM
Yes. My code for sending the serialized form look like this.

function savesomething(){
var formjson = JSON.stringify($('#examforms').serializeObject());
var urlprocess = "<%=oProp.ScriptPath+[?action=saveexam]%>";

  url: urlprocess,
  type: 'POST',
  data: { examformjson: formjson },
  beforeSend: function() {
    notify('Saving exams...', 'Please wait...', {
        icon: 'img/demo/icon.png'
  complete: function() {
      // hide indicator
      setTimeout(function() {
        document.location.href = '<%=oProp.ScriptPath +[?action=showsavedexam]%>' ;
        }, 2000);
  success: function(data) {

In my PRG it looks like this.

CASE oProp.Action=="saveexam"
oJSON=NEWOBJECT('json2')        && need to use JSON2 since JSON (orig) is broken on this aVFP version.
oJSON.ParseRespectClass = .T.
m.rawJsonString = oRequest.Form("examformjson")
m.rawJsonObj= m.oJSON.Parse(m.rawJsonString)
IF VARTYPE(m.rawJsonObj) = 'O'
    *-- parsing goes here

Oct 17, 2013 at 11:33 PM
Edited Oct 17, 2013 at 11:38 PM
json2 in NEWOBJECT is basically CraigBoyd's code

BTW: The json codes are working on version 553. I haven't migrated this project to the latest version.
Oct 18, 2013 at 4:02 PM
Hi apaustria,

Great. I could see why I was having this pesky problem, on first line of your mail.

I was using $('form.ajax') instead of $('#examforms'). I keep forgetting 'mobile' part of 'JQuery mobile'. ..And, as usual, I first blame AVFP.

Interesting use of serializeObject(). Is this something you wrote? If you share it then, I'll definitely use it.

Currently, our server side 'submit handler', needs to work with or without javascript enabled, and expects same values of oRequest.form() in both instances, but I am open to improvement.

Regarding Json, I've only changed the Json.prg back to it's original. the rest is the same. I can't report any error from this changes, till now.

Haven't checked oJSON.parse() though.

Oct 18, 2013 at 5:40 PM
Edited Oct 18, 2013 at 5:49 PM
I didn't originally wrote the code, can't remember though where I got it (stackoverflow maybe), but this does the job for me. :)
    $.fn.serializeObject = function()
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
        return o;
I think it's originally from here:
Oct 18, 2013 at 10:31 PM

I did see that one, but I ignored, it since it was not part of CDNs and was not sure if you meant the same function. I must say, you had a very unique way of using it.

Now I wish we could get all form variables that way form HTTPs reqst. It'll be just like using TableName.FieldName. very nice.

Oct 20, 2013 at 3:07 PM
Now I wish we could get all form variables that way form HTTPs reqst. It'll be just like using TableName.FieldName. very nice.

We've been able to do this for a while:
* Note the use of oRequest.oRequest to get these variables
FOR EACH lcFormVar IN oRequest.oRequest.FORM
    lcVar =   oRequest.oRequest.FORM(lcFormVar).ITEM()
    lcSTR=lcSTR+[    <TR><TD><b> ]+ lcFormVar +[ </b></TD><TD> ] ;
        +lcVar +[</TD></TR>] 
Anything you can do in Classic ASP, you can do in AVFP, plus all the great things FoxPro does!
Oct 22, 2013 at 12:07 AM
Good point claudefox.