Quantcast
Channel: SCN : Blog List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 676

READ & WRITE JSON API from HANA

$
0
0

Utilizing the most recent HANA XS engine web server ability, the mobile device can directly communicate to HANA appliance via HTTP protocol.  This simplifies the system architecture and extends HANA to all kinds of possibilities.

 

HTTP body in JSON format in WRITE API

 

ROOT {

 

  "name1" : "value1",

 

  "arrayname1": [ "arrayvalue11", "arrayvalue12" ],

 

  "name2" : "value2"

 

  "arrayname2" : [ "arrayvalue21", "arrayvalue22" ]

 

}

 

Parsing JSON in HANA:

 

var body = $.request.body.asString();

var obj = JSON.parse(body);

var name1 = obj.name1;

var name2 = obj.name2;

var arrayname1 = obj.arrayname1;

var arrayname2 = obj.arrayname2;

var i = 0

for (i; i< arrayname1.length; i++){

//write to HANA

}

 

HTTP body in JSON format in READ API:

{"entry":[

                    [    

                            ["name11","value11"],

                             ["name21", "value21"]

                    ],

                    [

                              ["name12","value12"],

                              ["name22","value21"]

                    ]

               ]

}

 

Constructing JSON in HANA:

var root = {

               entry: []

}

 

//rs is the return of table data

while (rs.next()){

     var jsonObj = [];

     var i = 1;

     for (i; i< columncount+1; i++){

          var record = [];

          record.push(columnlabel, rs.getString(i));

          jsonObj.push(record);

     }

     root.entry.push(jsonObj);

}

 

The JSON constructed from HANA this way is valid; however, it seems not necessarily represent the object array concept well.  Hope to see alternative approach.

These JSON format http body are either constructed in iPhone or consumed in iPhone for display.


Viewing all articles
Browse latest Browse all 676

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>