我玩得很开心
- 雷迪斯
- 网盘
- 镖
我写了这个
#import('dart:html');
#import('dart:json');
class ChatClient {
XMLHttpRequest listener;
int parsePosition = 0;
void connect(){
this.listener = new XMLHttpRequest();
this.listener.open("GET", "http://i.target.co.uk:9005/subscribe/test.json", true);
this.listener.setRequestHeader('Accept', 'application/json');
this.listener.on.readyStateChange.add(handleData);
this.listener.send();
}
void handleData(Event event){
print(this.listener.responseText);
/*
if (this.listener.responseText != ""){
Map data = JSON.parse(this.listener.responseText);
print(data["subscribe"]);
}
*/
}
}
void main(){
ChatClient client = new ChatClient();
client.connect();
document.query('#status').innerHTML = 'Loaded!';
}
问题是,每次我发布一些东西时,responseText 的大小都会像这样增长
{"subscribe":["subscribe","test",1]}
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}{"subscribe":["message","test","e"]}
现在你无法解析
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}{"subscribe":["message","test","e"]}
那我该怎么办?你能清除responseText吗?冲洗缓冲区?某物?
编辑:我知道您可以迭代整个字符串或跟踪每个 json 对象的长度,但没有更清洁的方法吗?
编辑:使用新的打印语句
readyStat: 2 status: 200
{"subscribe":["subscribe","test",1]}
readyStat: 3 status: 200
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}
readyStat: 3 status: 200