Page 1 of 1

how to insert JSON data

Posted: Mon Feb 12, 2018 9:41 am
by SamsonA
Hi, please, tell me, how to insert JSON data array into JS code?

JSON:
Code: Select all
[
   {"pos":"0","c1":13,"c2":71,"c3":47,"c4":77,"p1":13,"p2":36,"p3":56,"p4":48},
   {"pos":"1","c1":63,"c2":70,"c3":82,"c4":4,"p1":25,"p2":51,"p3":5,"p4":16}
]


JSON data array into JS code:
Code: Select all
...
   "fontSize":10,
   "fontFamily": "Nina",
   "data":
  [
     {"pos":"0","c1":13,"c2":71,"c3":47,"c4":77,"p1":13,"p2":36,"p3":56,"p4":48},
     {"pos":"1","c1":63,"c2":70,"c3":82,"c4":4,"p1":25,"p2":51,"p3":5,"p4":16}
  ]


SP
Code: Select all
   Structure myDataHisto
    pos.s
    c1.d
    c2.d
    c3.d
    c4.d
    p1.d
    p2.d
    p3.d
    p4.d
 EndStructure

Dim ppp.myData(1)
  For i=0 To 1
    ppp(i)\pos= Str(i)
    ppp(i)\c1 = Random(100,0)
    ppp(i)\c2 = Random(100,0)
    ppp(i)\c3 = Random(100,0)
    ppp(i)\c4 = Random(100,0)
    ppp(i)\p1 = Random(100,0)
    ppp(i)\p2 = Random(100,0)
    ppp(i)\p3 = Random(100,0)
    ppp(i)\p4 = Random(100,0)
  Next

tmp= CreateJSON(#PB_Any)
InsertJSONArray(JSONValue(tmp), ppp())
debug  ComposeJSON(tmp) 
; [ {"pos":"0","c1":13,"c2":71,"c3":47,"c4":77,"p1":13,"p2":36,"p3":56,"p4":48}, "pos":"1","c1":63,"c2":70,"c3":82,"c4":4,"p1":25,"p2":51,"p3":5,"p4":16}]

;...

; JS into SB

!    v_dat = p_tmp.array;
!   "fontSize":10,
!   "fontFamily": "Nina",
!   "data": v_dat