Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Problems with Alpha's Implementation of JSON vs. the changes in Build 2669-3921

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problems with Alpha's Implementation of JSON vs. the changes in Build 2669-3921

    Hello all,

    I wanted to make a quick post about Alpha's Implementation of JSON, mainly, it <del>is</del> was incorrect. I had been working on integrating Google Calendar into my Alpha application. It was going pretty good until I started working on the Google API integration. The latest version of the Google API (v3 for Calendar) accepts and returns JSON. I had many many problems working with the JSON functions in Alpha. They would not work on the data that I would get back from Google. Then when I would create a pointer structure and use varToJSON to send data back to Google, they would not accept it because it was malformed JSON.

    Because of this, I did some research and came to the conclusion that Alpha has implemented JSON incorrectly. According to json.org, as well as the IETF RFC 4627, the names of the variables should be enclosed in quotes (from all their examples, it's double quotes). Alpha does not enclose the names of the variables in quotes at all, which makes it more akin to a javascript object, echo'd out as a string, instead of JSON. (There is a distinctive difference). That is the largest error, but there are others, such as a5_json_prep function stripping out null values, when the JSON spec specifically states that null is a valid value. I have submitted some bug reports for the JSON functions in Alpha, but have not heard anything back related to those (it's been a few months). Realizing that Alpha wasn't going to change these functions any time soon, I was forced to use PHP as an intermediary between Google and my Alpha application. (Which has been working great).

    Anyways, the reason I'm writing a post about it today is because in the latest pre-release version, the changelog has information on some new JSON functions. And it looks like they're working correctly! (Although the example they give is incorrect, can't win 'em all)

    Code:
    dim text as c
    text = "{\"name\": \"John Smith\", \"married\": true, \"age\": 35, \"nul\": null }"
    ?text
    = {"name": "John Smith", "married": true, "age": 35, "nul": null }
    dim p as p
    p = INET::JSONParser::parse(text)
    
    ?p.name
    = "John Smith"
    ?p.married
    = .T.
    ?p.age
    = 35
    ?p.nul
    = <No data returned>
    
    ?vartojson(p)
    = {
        name: 'John Smith',
        married: true,
        age: 35
    }
    
    ?vartojsonstandard(p)
    ERROR: Variable type mismatch: attempt to pass data of type 'V' to argument 'var ' is of type 'C'.
    
    'After removing the null
    ?vartojsonstandard(p)
    = {
        "name": "John Smith",
        "married": true,
        "age": 35
    }
    Note: The vartojson function returns malformed JSON, but the (undocumented?) vartojsonstandard function returns correct! JSON. Success!!

    The first example from json.org also seems to work right off the bat!
    Code:
    dim text2 as c = "{\"glossary\": {\"title\": \"example glossary\",\"GlossDiv\": {\"title\": \"S\",\"GlossList\": {\"GlossEntry\": {\"ID\": \"SGML\",\"SortAs\": \"SGML\",\"GlossTerm\": \"Standard Generalized Markup Language\",\"Acronym\":\"SGML\",        \"Abbrev\": \"ISO 8879:1986\",\"GlossDef\": {\"para\":\"A meta-markup language, used to create markup languages such as DocBook.\",\"GlossSeeAlso\": [\"GML\", \"XML\"]},\"GlossSee\": \"markup\"}            }        }    }}"
    So, in conclusion, this post started out as a rant when I saw the changes in the changelog.
    But, half way through the post I installed the beta, and tested the functions and the post turned into a success!
    So thank you Selwyn and co. for fixing the issues I've had with the JSON implementation, but here's to hoping you deprecate and remove the incorrect functions (or at least name them javascript object instead of JSON)
    I will soon be converting all my php back into xbasic so I can, once again, have a 100% Alpha app.

    PS: It would be amazing if the examples, both in the changelog and the wiki, could be corrected to not discourage and confuse future developers.

    EDIT: PPS: The null value bug has been fixed in the next build!

    References:
    www.json.org
    http://www.ietf.org/rfc/rfc4627.txt?number=4627

    Thanks for listening!
    Last edited by Sparticuz; 05-09-2012, 11:35 AM.

    #2
    Re: Problems with Alpha's Implementation of JSON vs. the changes in Build 2669-3921

    We have introduced two new functions:
    json_parse()
    json_generate()

    json_parse() is just a wrapper around inet::jsonparser.parse(), which is a bit of a mouthfull.
    obviously as its name suggests, this function parses a string in json format and returns an xbasic dot variable.

    json_generate() does the opposite. it generates a string in json format from an xbasic dot variable.

    json_generate() just wraps varToJsonStandard(), which generates JSON in accordance with the official spec.

    varToJson() and varToJsonStandard() will be deprecated eventually.
    varToJson() differs from varToJsonStandard() in that it does NOT quote attribute names and is uses single quotes for string values. This is not the official json spec, but all browers support it and it is easier to write and read.

    so, in summary, once you have the latest patch use json_parse() to parse json and json_generate() to generate json.

    here is an interactive window session (showing that the javascript null object is preserved)




    Code:
    dim text as c
    text = "{\"name\": \"John Smith\", \"married\": true, \"age\": 35, \"nul\": null }"
    p = json_parse(text)
    ?*variable_to_script(P)
    = DIM name as C = "John Smith"
    DIM married as L = .T.
    DIM age as N = 35
    DIM nul as V
    
    ?json_generate(p)
    = {
    	"name": "John Smith",
    	"married": true,
    	"age": 35,
    	"nul": null
    }

    Comment


      #3
      Re: Problems with Alpha's Implementation of JSON vs. the changes in Build 2669-3921

      Thanks for the reply, Selwyn!

      I did encounter some of the json without quotes working in some of the things that I did in browser, but Google API didn't accept it as well as some jQuery plugins being picky about it. Having these new functions really opens the door to interactivity with REST services and API's.

      I'm really excited about the new functions.

      Comment


        #4
        Re: Problems with Alpha's Implementation of JSON vs. the changes in Build 2669-3921

        I cannot explain how happy I am with the new json_generate() and json_parse() functions !!

        Things have changed tremendously for me now in terms of using REST services and APIs and most recently implementing javascript libraries such as JQuery scheduling components. The latest Release Candidate cleans up JSON because previous to this I had to be using PHP webservices to query my database and returning clean JSON results.

        Now I can use Alpha Five ! So I join in with Sparticuz's celebration of good times ahead.

        Comment

        Working...
        X