Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't parse json from allocine #25

Closed
pasnox opened this issue May 14, 2013 · 13 comments
Closed

Can't parse json from allocine #25

pasnox opened this issue May 14, 2013 · 13 comments

Comments

@pasnox
Copy link

pasnox commented May 14, 2013

The parser ( tested in both branches, master / 1.0.0 ) is not able to parse correctly content from AlloCiné.
You can get a copy of the json here: http://api.allocine.fr/rest/v3/movie?code=53300&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130514&sig=rD6tw9RCQS3dpccdrYMyD3gWhk4%3D

The parser return false, but strangely the returned qvariant seem to have some content inside ?

Thanks,

@pasnox
Copy link
Author

pasnox commented May 14, 2013

I found the origin of the problem.
I was reusing the same parser to parse multiple data.
Doing that result in some parsing problems.
When recreating the parser each time, the problem disappear.

@flavio
Copy link
Owner

flavio commented May 15, 2013

That's not good, I'm going to fix the issue.

@flavio
Copy link
Owner

flavio commented May 15, 2013

I have some problems reproducing the issue, could you paste the json file here? I cannot access it anymore.

@pasnox
Copy link
Author

pasnox commented May 15, 2013

Just now i can't. But the probleme is easily reproductible with random json.
Just create one parser, and use it to parse multime json content ( which u can store in a QList of QByteArray by example).

@flavio
Copy link
Owner

flavio commented May 15, 2013

I cannot reproduce the issue. I tried to parse the same json data 3 times in a row using the same parser. I've also tried to parse a json object followed by another one (all repeated 3 times) but nothing happened.

Do you know how to reproduce the issue?

@pasnox
Copy link
Author

pasnox commented May 15, 2013

In my test, i was parsing around 10 different json content. i will try to create a testcase tomorrow and send u.

@pasnox
Copy link
Author

pasnox commented May 17, 2013

Hi,

Here is a crappy export of the incrimined code that should reproduce the problem.
Url are presented to u as encoded one.
Feel free to reuse the sample and adapt with the request content.
Do quick, the url are valid only today (french hours).

Regards,

Url 1: "http://api.allocine.fr/rest/v3/search?count=10&filter=movie&format=json&page=1&partner=100043982026&q=scary%20movie&sed=20130517&sig=Z8Sv%2BI1GadnhbwC%2BluLRC5sRpxM%3D"
Url 2: "http://api.allocine.fr/rest/v3/movie?code=26077&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130517&sig=Kb95eJl0iQezPBaXGN8Q0EELGjI%3D"
Url 3: "http://api.allocine.fr/rest/v3/movie?code=28914&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130517&sig=h6dlYGd%2B8pmfPAg8qGE6%2BvDlQAU%3D"
Url 4: "http://api.allocine.fr/rest/v3/movie?code=112361&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130517&sig=08LGmfQKxSvTU4DLC8%2BeUTkV2wQ%3D"
Url 5: "http://api.allocine.fr/rest/v3/movie?code=52500&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130517&sig=SfkHevwFf4YrUBN%2B8tCmge%2BfUb4%3D"
Url 6: "http://api.allocine.fr/rest/v3/movie?code=41325&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130517&sig=95ta9bSNu%2FmDvkMny%2BBBawdhGV4%3D"
Url 7: "http://api.allocine.fr/rest/v3/movie?code=53300&format=json&mediafmt=mp4-hip&partner=100043982026&profile=large&sed=20130517&sig=F8WXByOqGKsv7X8KGR7EZErPux8%3D"
    QJson::Parser parser;
    bool ok;
    QVariantMap json = parser.parse( data.toUtf8(), &ok ).toMap(); // data is reply for url 1

    const QVariantMap feed = json[ "feed" ].toMap();
    const QVariantList movies = feed.value( "movie" ).toList();

    if ( !ok || feed.isEmpty() ) {
        qWarning() << "JSon error:" << parser.errorString();
        return;
    }

    foreach ( const QVariant& variant, movies ) {
        QVariantMap movie = variant.toMap();
        const QString id = movie.value( "code" ).toString();

        if ( id.isEmpty() ) {
            continue;
        }

        QNetworkReply* reply = createReply( id, driver ); // url for each movie, represented by url 2 to 7, the call is normally sync by using a QEventLoop, but feel free to get all json, and loop over a lsit of QByteArray as alternative to using QNAM.

        if ( !reply ) {
            continue;
        }

        const QByteArray releaseData = reply->readAll(); // bytearray of current reply
        json = parser.parse( releaseData, &ok ).toMap();
        reply->deleteLater();

        if ( !ok ) { // normally if u reproduce the bug, u should receive here bad result for good json ( except for url returning ip loggued error from the server )
            qWarning() << "JSon error:" << parser.errorString();
            continue;
        }

        movie = json.value( "movie" ).toMap();
        qWarning() << movie;
    }

@moio
Copy link
Contributor

moio commented May 17, 2013

A copy of the json files is available here in case more time is needed:

http://www.moioli.net/temp/allocine-json-files.tar.gz

flavio added a commit that referenced this issue May 17, 2013
@flavio
Copy link
Owner

flavio commented May 17, 2013

Ok, I quickly adapted the code I wrote to use the json data you posted. Unfortunately I cannot reproduce it.

Could you take a look at commit 550cada (which is inside of the issue_25 branch) and tell me if something is missing?

@flavio
Copy link
Owner

flavio commented May 17, 2013

@pasnox could you checkout this branch and run the unit tests? That would be really useful.

@pasnox
Copy link
Author

pasnox commented May 17, 2013

Hi,

I recall that for having the bug, at least one of the json content received was an error ip loggued from server.
So in the loop, consider adding a bad json content at the middle or random place so on parse fails.

Goog / Bad / Goog / Good / Good / Good / Bad / Bad / Good may be a good test.

flavio added a commit that referenced this issue Jul 18, 2013
Ensure the same parser can be used multiple times in a row, even if a
parsing error is found.
@flavio
Copy link
Owner

flavio commented Jul 18, 2013

Fixed on master.

@flavio flavio closed this as completed Jul 18, 2013
@pasnox
Copy link
Author

pasnox commented Jul 21, 2013

Great! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants