How to host a json file using ActiveVFP

Topics: Developer Forum
Jul 30, 2014 at 9:46 AM
Hi everyone,

I am looking to host a JSON file, where other applications will be able to download it and parse it. I am using a MSSQL database, and look to convert SQL result to the JSON file. Can this be done using ActiveVFP?
Coordinator
Jul 30, 2014 at 5:43 PM
Edited Jul 30, 2014 at 5:47 PM
Absolutely. See the MSSQL example in the demo and just apply the JSON example code to the data you pull up from SQL.
http://www.rootsofmine.com/avfp603/customers/getemployees
    oJSON=NEWOBJECT('json','json.prg')
    
    SET PATH TO oProp.AppStartPath+'data\AVFPdemo41\'
    
    select e.emp_id as id, e.first_Name as firstName, e.last_Name as lastName, e.title as title, [images/Emps/]+e.picture as picture,count(r.emp_id) as reportCount ;
    from employee e left join employee r on VAL(r.reports_to) = VAL(e.emp_id) ;
    INTO Cursor SearchResults;
    group by e.last_Name,e.emp_id, e.first_Name,e.title, e.picture ;
    order by e.last_Name,e.first_Name
  

    oJSON.keyforcursors="items"

    * send JSON data and properties back
    oResponse.ContentType = "application/json;charset=utf-8"  
    oResponse.Write(oJSON.stringify('SearchResults'))
    oResponse.Flush
    return []