implement JStest include sys sys Sys include draw include json json JS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
implement JStest;
include "sys.m";
sys: Sys;
include "draw.m";
include "json.m";
json: JSON;
include "bufio.m";
bufio: Bufio;
JStest: module {
init: fn(ctx: ref Draw->Context, argv: list of string);
};
init(nil: ref Draw->Context, nil: list of string){
sys = load Sys Sys->PATH;
json = load JSON JSON->PATH;
bufio = load Bufio Bufio->PATH;
JValue: import json;
buffd := bufio->open("3.json", Sys->OREAD);
json->init(bufio);
(jval, err) := json->readjson(buffd);
if(jval == nil) { sys->print("err: %s|%r\n", err); exit; }
sys->print("isarray flag: %d\n", jval.get("response").isarray());
# keys := array[] of {"uid", "first_name", "last_name", "nickname"};
cnt := 0;
while(cnt != 3){
child := jval.get("response");
if(child == nil) { sys->print("child break\n"); exit;}
sys->print("jval --%d --%s\n\n", cnt, jval.get("uid").text());
}
}