Dear Team,
Iam inserting the JsonData into the Datawindow...Iam unable to resolve this ..Please help me..
String ls_jsonString
String ls_value
String ls_key
String ls_firstname
Long ll_RootObject
Long ll_rowitem
Long ll_count
Long ll_array
Long ll_arraycount
Long ll_arrayitem
Int ll_rowindex
Int ll_arrayindex
Int li_id,ll_row
JSONParser jsonParser
// JSON
ls_jsonString = '[{"ID":101,"FirstName":"Li"},{"ID":102,"FirstName":null},{"ID":103,"FirstName":"Li"},{"ID":104,"FirstName":null},{"ID":105,"FirstName":"Li"},{"ID":106,"FirstName":null},{"ID":107,"FirstName":"Li"},{"ID":108,"FirstName":null},{"ID":109,"FirstName":"Li"},{"ID":110,"FirstName":null},{"ID":111,"FirstName":"Li"}, {"ID":112,"FirstName":[{"Mode":"email","value":"john@hotmail.com"},{"Mode":"phone","value":[{"Mode":"fax","value":"11111111"},{"Mode":"fax2","value":"2222222"}]}]}, {"ID":113,"FirstName":"Li"},{"ID":114,"FirstName":null},{"ID":115,"FirstName":"Li"}, {"ID":116,"FirstName":[{"Mode":"email","value":"john@example.com"},{"Mode":"phone","value":"555-123-4567"}]}]'
jsonParser = create JSONParser
jsonParser.LoadString(ls_jsonString)
ll_RootObject = jsonParser.GetRootItem()
ll_count = jsonParser.GetChildCount(ll_RootObject)
// Each object
For ll_rowindex = 1 to ll_count
ll_rowitem = jsonParser.GetChildItem(ll_RootObject, ll_rowindex)
// Each item
li_id = jsonParser.GetItemNumber(ll_rowitem, "ID")
ls_firstname = ""
ls_key = "FirstName"
Choose Case jsonParser.GetItemType(ll_rowitem, ls_key)
case JsonStringItem!
ls_firstname = jsonParser.GetItemString(ll_rowitem, ls_key)
case JsonNullItem!
ls_firstname = 'Null'
Case JsonArrayItem!
// Parse FirstName Array
ls_firstname = " "
ll_array = jsonParser.GetItemArray( ll_rowitem, ls_key )
ll_arraycount = jsonParser.GetChildCount(ll_array)
For ll_arrayindex = 1 to ll_arraycount
ll_row = dw_1.insertrow(0)
ll_arrayitem = jsonParser.GetChildItem(ll_array, ll_arrayindex)
Choose Case jsonParser.GetItemType(ll_arrayitem, "value")
Case JsonStringItem!
messageBox("", "Mode: " + jsonParser.GetItemString(ll_arrayitem, "mode") + " " + &
" Value: " + jsonParser.GetItemString(ll_arrayitem, "value"))
Case JsonArrayItem!
// TODO: Parse Value Array
// ...
End Choose
//Insert the data into data window
dw_2.setitem(ll_row, 'id', jsonParser.GetItemNumber(ll_arrayitem, "id"))
dw_2.setitem(ll_row, 'FirstName', jsonParser.GetItemString(ll_arrayitem, "FirstName"))
dw_2.setitem(ll_row, 'Mode', jsonParser.GetItemNumber(ll_arrayitem, "Mode"))
dw_2.setitem(ll_row, 'value', jsonParser.GetItemstring(ll_arrayitem, "value"))
Next
End Choose
MessageBox("Row - ID: " + String(li_id), "FN: " + ls_firstname)
Next