Hi,
Here is my code for generating JSON file from datawindow. it shows some issues.
The out put should show like below
[ { "postId": 1, "id": 1, "name": "id labore ex et quam laborum", "email": "Eliseo@gardner.biz", "body": "laudantium enim " }, { "postId": 1, "id": 2, "name": "quo vero reiciendis velit similique earum", "email": "Jayne_Kuhic@sydney.com", "body": "est natus enim nihil " }, ] but i get result like this { "postId": 1, "id": 1, "name": "id labore ex et quam laborum", "email": "Eliseo@gardner.biz", "body": "laudantium enim quasi est" , "postId": 1, "id": 2, "name": "quo vero reiciendis velit similique earum", "email": "Jayne_Kuhic@sydney.com", "body": "est natus enim nihil est" },
//////////////////////////////// Function for generating JSON ////////////////////////////////////////////////////////////////
long ll_index, ll_count, ll_root
String ls_json
long columns ,ll_col_index , ll_col_count,ln_long ,ll_RootArray
string ls_colname,ls_datastring,coltype,ls_string
dec ld_dec
datetime ld_dattime
int lint
HttpClient hc
JSONGenerator jg
hc = create HttpClient
jg = create JSONGenerator
this.AcceptText()
ll_count = this.Rowcount( )
ll_col_count = integer(this.object.datawindow.column.count)
ll_root = jg.createjsonobject( )
FOR ll_index = 1 TO ll_count
// ll_root =jg.CreateJsonArray()
coltype =UPPER(LEFT( this.Describe(ls_datastring),3))
for ll_col_index = 1 To ll_col_count
ls_colname = this.describe('#'+string(ll_col_index)+'.name')
ls_datastring = ls_colname+"."+"Coltype"
coltype =UPPER(LEFT( this.Describe(ls_datastring),3))
if coltype = "CHA" then
ls_string = this.GetItemString(ll_index, ls_colname )
if isnull(ls_string) then
jg.AddItemNull (ll_root, ls_colname )
else
jg.AddItemString(ll_root, ls_colname ,ls_string)
end if
elseif coltype = "DAT" then
ld_dattime= this.GetItemDateTime (ll_index, ls_colname )
if isnull(ld_dattime) then
jg.AddItemNull (ll_root, ls_colname )
else
jg.AddItemDateTime(ll_root, ls_colname , ld_dattime )
end if
elseif coltype = "DEC" then
ld_dec =this.GetItemNumber(ll_index, ls_colname)
if isnull(ld_dec) then
jg.AddItemNull (ll_root, ls_colname )
else
jg.AddItemNumber(ll_root, ls_colname , ld_dec)
end if
elseif coltype = "LON" then
ln_long =this.GetItemNumber(ll_index, ls_colname)
if isnull(ln_long) then
jg.AddItemNull (ll_root, ls_colname )
else
jg.AddItemNumber(ll_root, ls_colname , ln_long)
end if
elseif coltype = "INT" then
lint =this.GetItemNumber(ll_index, ls_colname)
if isnull(ln_long) then
jg.AddItemNull (ll_root, ls_colname )
else
jg.AddItemNumber(ll_root, ls_colname , lint)
end if
else
messagebox('info','Data type undefined')
end if
Next
NEXT
ls_json = jg.getjsonstring( )
messagebox('', ls_json )
Thanks
Shijilesh