Wednesday, March 21, 2012

Re: [YouTube-API] Parsing youtube data with C++ and Jsoncpp

I don't think I've done any JSON parsing with Jsoncpp, but I'm confused
about what you're doing with the entries.

value["feed"]["entry"] is an Array (JSON Array).

The modified string (i.e. without the "[" and "]") isn't a valid JSON
string, and you should be getting parse errors trying to parse it as
JSON.

I'd fix that issue and make sure your error handling is set up correctly
before trying anything else (I'd expect parse errors here, and you're
not checking any return values, so it's possible you're missing library
errors)

Tim Wintle

On Tue, 2012-03-20 at 08:54 -0700, Mare wrote:
> I'm not quite sure is this right place to ask about this but my
> problem is following:
>
>
> Here is an example feed that I would like to
> parse:https://gdata.youtube.com/feeds/api/users/aniBOOM/subscriptions?v=2&alt=json
>
> You can check it with http://json.parser.online.fr/ to see what it
> contains.
>
> I have a small problem while parsing data feed provided by youtube.
> First issue was the way the youtube provided the data wrapped inside
> feed field and because of that I couldn't parse the username straight
> from original json file so I had to parse first entry field and
> generate new Json data from that.
>
> Anyway the problem is that for some reason that doesn't include more
> than the first username and I don't know why because if you check that
> feed on online parser the entry should contain all the usernames.
>
> 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);
> But for some reason [] fix also cuts the data I'm generating, if I print out the data without removing [] I can see all the users but in that case I can't extract temp = value2["yt$username"]["yt$display"];
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "YouTube APIs Developer Forum" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/youtube-api-gdata/-/lff_wiHYFvsJ.
> To post to this group, send email to
> youtube-api-gdata@googlegroups.com.
> To unsubscribe from this group, send email to youtube-api-gdata
> +unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/youtube-api-gdata?hl=en.


--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment