如何通过d语言阅读推特json

如何通过d语言阅读推特json,json,d,Json,D,我有一个推特json(保存在一个名为latest.json的文件中),我将其解析为“jasonvalue doc”,并尝试读取它并打印特定数据。下面的代码每次都打印相同的数据,而不是构成整个json的数据 auto content = to!string(read("latest.json")); JSONValue doc = parseJSON(content).object; while (i<3){ writeln(doc.object["created_at"].s

我有一个推特json(保存在一个名为latest.json的文件中),我将其解析为“jasonvalue doc”,并尝试读取它并打印特定数据。下面的代码每次都打印相同的数据,而不是构成整个json的数据

auto content = to!string(read("latest.json"));
 JSONValue doc = parseJSON(content).object; 
 while (i<3){
    writeln(doc.object["created_at"].str,"\n");
    writeln(doc.object["text"].str,"\n");
    writeln(doc.object["retweet_count"].integer,"\n");
    i++;
 }
auto content=to!字符串(读取(“latest.json”);
JSONValue doc=parseJSON(content.object);

while(i您应该在项目数组上循环。从twitter获取json,就像这里的示例:它作为一个对象数组出现

我也是


这应该可以解决问题。

哦,糟糕,我忘了输入[]。如果你有一个
JSONValue[],它应该可以工作。
当我现在运行程序时,tweet将是parseJSON.array返回的数组的一个成员,它说:“std.json。JSONExcetion@std\json.d:JSONvalue不是数组“
JSONValue[] doc = parseJSON(content).array;
foreach(tweet; doc) {
    writeln(tweet.object["text"].str);
     // and other info
}