这是我想解析的示例提要: https ://gdata.youtube.com/feeds/api/users/aniBOOM/subscriptions?v=2&alt=json
您可以通过http://json.parser.online.fr/查看它包含的内容。
我在解析 youtube 提供的数据提要时遇到了一个小问题。第一个问题是 youtube 提供包含在 feed 字段中的数据的方式,因此我无法直接从原始 json 文件解析用户名,所以我必须解析第一个输入字段并从中生成新的 Json 数据。
无论如何,问题是由于某种原因不包括第一个用户名,我不知道为什么,因为如果您在在线解析器上检查该提要,则该条目应包含所有用户名。
`
data = value["feed"]["entry"];
Json::StyledWriter writer;
std::string outputConfig = writer.write( data );
//This removes [ at the beginning of entry and also last ] so we can treat it as a Json data
size_t found;
found=outputConfig.find_first_of("[");
int sSize = outputConfig.size();
outputConfig.erase(0,1);
outputConfig.erase((sSize-1),sSize);
reader.parse(outputConfig, value2, false);
cout << value2 << endl;
Json::Value temp;
temp = value2["yt$username"]["yt$display"];
cout << temp << endl;
std::string username = writer.write( temp );
int sSize2 = username.size();
username.erase(0,1);
username.erase((sSize2-3),sSize2);
` 但由于某种原因,[] 修复也削减了我正在生成的数据,如果我在不删除 [] 的情况下打印出数据,我可以看到所有用户,但在这种情况下,我无法提取 temp = value2["yt$username "]["yt$display"];