GithubHelp home page GithubHelp logo

Can't parse json from allocine about qjson HOT 13 CLOSED

flavio avatar flavio commented on August 27, 2024
Can't parse json from allocine

from qjson.

Comments (13)

pasnox avatar pasnox commented on August 27, 2024

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.

from qjson.

flavio avatar flavio commented on August 27, 2024

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

from qjson.

flavio avatar flavio commented on August 27, 2024

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

from qjson.

pasnox avatar pasnox commented on August 27, 2024

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).

from qjson.

flavio avatar flavio commented on August 27, 2024

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?

from qjson.

pasnox avatar pasnox commented on August 27, 2024

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

from qjson.

pasnox avatar pasnox commented on August 27, 2024

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;
    }

from qjson.

moio avatar moio commented on August 27, 2024

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

from qjson.

flavio avatar flavio commented on August 27, 2024

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?

from qjson.

flavio avatar flavio commented on August 27, 2024

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

from qjson.

pasnox avatar pasnox commented on August 27, 2024

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.

from qjson.

flavio avatar flavio commented on August 27, 2024

Fixed on master.

from qjson.

pasnox avatar pasnox commented on August 27, 2024

Great! thanks

from qjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.