JsonDataAccess problem

Hello

IAM trying to load a json file ive downloaded. (Download works, checked if the file already exists in my "data / blabla.json")

But now, when I try to use JsonDataAccess, it returns the following error during the generation

expected ';' before 'jda' OR 'JsonDataAccess' was not declared in this scope

the only thing I did:

#include /* ... */void app::parseJson(){    if (json->exists()) {
    JsonDataAccess jda;
    }}

Does anyone have an idea?

THX

EDIT

After you have added

using namespace bb::data;

It worked!

Of course

In your header file to register the slots and the vars

private slots:   void requestFinished(QNetworkReply *reply);

private:   QNetworkAccessManager *mNetworkAccessManager;   QFile *file;

for example (pseudocode)

App.h

#ifndef APP_H_
#define APP_H_
//* includes & namespaces here *//class App{public:
    App();    Q_INVOKABLE void init();

private slots:
    void requestFinished(QNetworkReply *reply);

private:
    QNetworkAccessManager *mNetworkAccessManager;
    QFile *json;
};

#endif /* APP_H_ */

Then in your constructor to create access like this manager network

mNetworkAccessManager = new QNetworkAccessManager(this);

then add the signals and slots and make sure to check out them after that

bool result = connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));

Q_ASSERT(result);
Q_UNUSED(result);

what I did to create the reference here file

json = new QFile("data/file.json");

Then call the method init to start on demand, I think the Q_INVOKABLE is necessary only when you call the init method of QML

init();

// init method looks like thisvoid App::init(){QNetworkRequest request = QNetworkRequest();    request.setUrl(QUrl("url to json"));    mNetworkAccessManager->get(request);}

and finally in the SLOT, we used requestFinished(QNetworkReply *reply) so that's how this method resembles

void App::requestFinished(QNetworkReply *reply){
    qDebug("Request finished");
    qDebug() << reply->error();
    qDebug() << reply->errorString();
    if (reply->error() == QNetworkReply::NoError) {
        qDebug() << "No error";

        QByteArray data = reply->readAll();

        if (!json->open(QIODevice::ReadWrite)) {
            qDebug() << "Failed to open file";
            return;
        }

        json->write(data);
        json->flush();
        json->close();

        qDebug() << "JSON file fetched and saved to 'data/file.json'";
}

I hope this helps.

Welcome,

Xtravanta

Tags: BlackBerry Developers

Similar Questions

  • Problem in the use of JSONDATAACCESS for parsing json getting as the server Http response.

    Hey Hi,

    I was tired this solution but get a problem. The problem is when I am trying to build my project it gives an error stating that ' expected ';' before ' ja ' when I declare JsonDataAccess.

    Here is my code snippet:

    JsonDataAccess ja;
    QString response;
    If (response-> error() == QNetworkReply::NoError) {}
    const int available = response-> bytesAvailable();
    If (available > 0) {}
    answer = QString::fromUtf8 (response-> readAll());
    qDebug()< "tag="" name="" is="" ::=""><>
    QVariant jsonva = ja.loadFromBuffer (response);

    }

    even after the addition of the LIBS +=-lbbdata in the .pro file I get no success here.

    Help, please

    Concerning

    Don't forget to:

  • JsonDataAccess bug?

    I try to analyze it:

    {
        "activities":[
            {
                "activityId":,
            },
           <..>
        ],
        "goals":{
            "activeScore":,
        },
        "summary":{
            "distances":[
                {"activity":"tracker", "distance":},
                {"activity":"loggedActivities", "distance":},
                <..>
            ],
            "elevation":,
            "veryActiveMinutes":
        }
    }
    

    And here is my code:

    void ApiResponse::parse(QByteArray data) {
        JsonDataAccess jda(new QObject);
        QVariant resp = jda.loadFromBuffer(data);
        if (resp.canConvert(QVariant::List)) {
            foreach(const QVariant &var, resp.toList()) {
                qDebug() << var;
            }
        } else if (response != NULL && resp.canConvert(QVariant::Map)) {
            response->parse(resp.toMap());
        }
    }
    

    So I expect to get a card that has 'activities', 'objective' and 'summary', but I get only 'activities '.  I checked this by placing a breakpoint at the beginning of the parse method.

    Is there something that I am missing so he could get the other objects?

    Edit: also after trying to debug even more that I noticed when I opened "resp." I see this:

    The data have 112 'p' tank, well, when I open the QByteArray and copy its values into notepad ++, I see two places that correspond to 112 'p', 84 char and char 558.  This could mean, he stopped the analysis or the other of these two points?  A memory problem?

    OK, I've printed version QString QByteArray, added to a file (results accurate, unmodified) and I always get only 'activities'.

    Edit, actually, when I break point on it, it only shows not her, but if I look at the value after I take for it, its here!  Strange that I can't see when we watch in the display of the Variables.  And I thought that it was not the case is because I had in my QML a label with the text: "active Score:" + activities.activeScore and he turned upward undefined, and he was showing undefined because I have another strong component of activities at the same time, I tried to link a q_object to this label. "  It's working now, thank you!

    See what you get with this:

    {
        "activities":[]
        ,"goals":
            {"activeScore":1000,
            "caloriesOut":2184,
            "distance":8.05,
            "steps":10000}
        ,"summary":
            {"activeScore":1,
                "activityCalories":0,
                "caloriesOut":1618,
                "distances":[
                    {"activity":"total","distance":0}
                    ,{"activity":"tracker","distance":0}
                    ,{"activity":"loggedActivities","distance":0}
                    ,{"activity":"veryActive","distance":0}
                    ,{"activity":"moderatelyActive","distance":0}
                    ,{"activity":"lightlyActive","distance":0}
                    ,{"activity":"sedentaryActive","distance":0}
                ]
                ,"fairlyActiveMinutes":0
                ,"lightlyActiveMinutes":0
                ,"marginalCalories":0
                ,"sedentaryMinutes":945
                ,"steps":0
                ,"veryActiveMinutes":0
            }
    }
    

    Edit: My guess is that its a problem with the activities being empty or the fact that the values are not strings.  Simply by looking at the difference between your example json and mine.

  • Problem, the signals and Slots

    Hi, as I posted in one of my other posts I have following problem with signals and messages and would be nice if someone could clarify anything that I don't seem to be able to find what the problem of the outputs.

    I have the code:

    void MYNetworkClass::requestFinished(QNetworkReply* reply)
    {
    
          // Check the network reply for errors
          if (reply->error() == QNetworkReply::NoError)
          {
             // read response
             const QByteArray response(reply->readAll());
             qDebug() <<"Response: "<< response;
    
             JsonDataAccess jda;
             QVariantMap results = jda.loadFromBuffer(response).toMap();
    
             QVariantMap data = results.value("SomeData").toMap();
    
             emit signalSuccess(data); // I reach here .... 
    
    // however actually when I click "Step Over" in debug mode, and try to exit the function// afterwards I get such "error" saying: No source available for "QMetaObject::activate() at  0xb9668da7" - highlighted in red.
    
         }
         else
         {
             qDebug() << "\n Problem with the network";
             qDebug() << "\n" << reply->errorString();
         }
    

    In MyNetwork class I also added the definition of signal in the header file:

    signals:
    
        void signalSuccess(QVariantMap result);
    

    Now also when someone calls an object MyNetworkClass method which calls requestFinished,.

    I want to catch the signal which is emitted by the requestFinished - as shown above.

         MyNetworkClass *network = new MyNetworkClass();
    
        QMap params;
        params.insert("username", userEmail);
    
        bool res = QObject::connect(network, SIGNAL(signalSuccess(QVariantMap)), this, SLOT(SomeSlotForSignal(QVariantMap)));
    
            Q_ASSERT(res);
        Q_UNUSED(res);
            network->makePostRequest("Login");
    

    My problem is that the SomeSlotForSignal slot never is called... (even if the signal is issued constitute requestFinished method and as I stated SomeSlotForSignal as a crack in the header file...) What can be problem? Any help? Thank you.

    I guess I solved the problem.

    The code I presented previously registered function

    F of a class B:

     void B::f()
    {
    MyNetworkClass *network = new MyNetworkClass();
    
        QMap params;
        params.insert("username", userEmail);
    
        bool res = QObject::connect(network, SIGNAL(signalSuccess(QVariantMap)), this, SLOT(SomeSlotForSignal(QVariantMap)));
    
            Q_ASSERT(res);
        Q_UNUSED(res);
    
    network->makePostRequest("Login");
    }
    

    Then the function f is called to:

        B object;
        object.f();
    
    The problem was I think that when the server responded "object" was destroyed from the stack. When I replaced the above code, with 
    
         B* object = new B();
        object->f();
    
    I think it works now......
    
  • JsonDataAccess error in JSON even report it is valid

    I have a problem with parsing JSON which I get from QNetworkReply. I checked on http://json.parser.online.fr/beta/ if json is valid and it is:

    {
        "status": 0,
        "objects": [{
            "id": "i_53909cc3eeafd",
            "name": "picture1",
            "location": [{
                "x": -5,
                "y": 126
            }, {
                "x": 266,
                "y": 126
            }, {
                "x": 269,
                "y": 396
            }, {
                "x": -5,
                "y": 400
            }]
        }]
    }
    

    I use following code:

    void ApplicationUI::onRequestFinished(QNetworkReply* reply) {
    
        QString response = QString::fromUtf8(reply->readAll());
    
        if(reply){
            if(reply->error() == QNetworkReply::NoError) {
    
                JsonDataAccess jsonDataAccess;
                QVariant list = jsonDataAccess.loadFromBuffer(response);
                if (jsonDataAccess.hasError()) {
                    DataAccessError error = jsonDataAccess.error();
                    qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
                    return;
                }
            } else {
                qDebug() << "Network error!";
            }
        }
    
    reply->deleteLater();
    }
    

    Everyt time I receive reply jsonDataAccess shows me error:

    JSON loading error:  3 :  "* Line 1, Column 1
      Syntax error: value, object or array expected.
    "
    

    The second problem is the fact that I am not able to access the values of this json response. I tried many possibilities and I always get empty results.

    OK, the problem is now resolved. I realized that my QNetworkAccessManager I had after the line:

    request.setRawHeader(QString("Accept-Encoding").toAscii(), QString("gzip,deflate").toAscii());
    

    Who was raping my JSON.

  • JsonDataAccess and Insertion of DB

    IAM having the following .json file

    [
        {
            "title" : "Mike",
            "titleArabic" : "Chepesky",
            "shortDesc":"[email protected]",
            "shortDescArabic":"1-234-567-8910",
    
        },
        {
            "title" : "Westlee",
            "titleArabic" : "Barichak",
            "shortDesc":"[email protected]",
            "shortDescArabic":"1-234-567-8910",
    
        },
        {
            "title" : "Ian",
            "titleArabic" : "Dundas",
            "shortDesc":"[email protected]",
            "shortDescArabic":"1-234-567-8910",
    
        }
    ]
    

    I need to parse this json file and insert the data into a table named 'How_To' in DB.

    Here's the code I used to parse json and insert data from DB

    void ApplicationUI::jsonParser()
    {
             JsonDataAccess jda;
            QVariant jsonva = jda.load("app/native/assets/data.json");
            if (jda.hasError())
                {
                    bb::data::DataAccessError error = jda.error();
                    qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
                    return;
                }
            else
            {
                 QVariantList list = jsonva.toList();
                 for (QList::iterator it = list.begin(); it != list.end(); it++)
                  {
                        QVariantMap map = it->toMap();                              qDebug(<
    

    My problem is:

    (1) there is no value available on the map that I created while reiterating the answer jsonDataAccess

    Where Iam wrong please help me

    Hi SumiSadiq,

    The problem is in the format of your .json file. Remove the comma after the value of the last attribute (shortDescArabic) it will do the job. I tried the code by using the sample application stampcollector and the map values were retrieved correctly on the console.

  • Problem in parsing Json

    I have a problem with parsing Json. While participating in the 1st time I would log on to the Console as

    "Jsonva length 21".
    JSON length 0 "

    After 2 or 3 attempts, I would log in the form

    "Jsonva length 21".
    JSON length 14 "

    Here I use to code analysis.

    BB::data :: JsonDataAccess ja;
    const QVariant jsonva = ja.loadFromBuffer (response);
    QList const externalip = jsonva.toList ();

    std::cout< "jsonva="" length1="" "="">< jsonva.size=""><>
    std::cout< "json="" length1="" "="">< externalip.size()=""><>

    Pls advice me what is the problem in my code.

    Sorry that was my problem. I have error in functionality.

    Thanks dude.

  • Unable to Scan to the computer after downloading macOS Sierra. Is this a software problem?

    How can I scan from HP Envy 4500 to computer after downloading macOS Sierra?

    Hello wdemetris,

    Thanks for asking for scanning helps here in the Apple Support communities. I understand how it is important to have access to your scanner and am happy to offer help for this.

    As a precaution, we always recommend that you have backups to make sure that all your data is safe. You can perform a backup using Time Machine and an external hard drive. Use this article to help make a backup of your Mac: use Time Machine to back up or restore your Mac.

    Then, in accordance with article help: printer and scanner for Sierra, El Capitan, Yosemite, and the Mavericks macOS software, the HP Envy 4500 e-all-in-one is supported for printing and scanning. The drivers must be installed, but if not, if it please go to the App Store and check the updates tab to see if there are updates for HP. If there is, please install.

    If you have only general questions about how to get your updated scanner in place or how to scan pictures, please check out these two articles: macOS Sierra: implement a scanner & macOS Sierra: scan images or documents. If everything is configured correctly and you still have problems scanning, please visit this help article: macOS Sierra: scanning troubleshooting.

    Thanks again and have a great rest of your day.

  • My iPhone 6 installed 10.0.2 stops when it gets to 40% of autonomy.  In addition, it seems to pass power WAY to fast with the new software.  Does anyone else have this problem?

    My iPhone 6 installed 10.0.2 stops when it gets to 40% of autonomy.  In addition, it seems to pass power WAY to fast with the new software.  Does anyone else have this problem?

    Hello brooksm549,
    Thank you for using communities of Apple Support.

    I got your message which, since updating your iPhone 6 to iOS 10.0.2 your iPhone stops when it is 40% and the power to empty very quickly. I understand your concern with the iPhone turn off and drains the battery. I recommend you to review the use of the battery to see what app contributes more to the battery drain. The following article will provide you with steps on how to check the use of the battery:

    On the use of the battery on your iPhone, iPad and iPod touch

    When you know about the soft uses more battery, you can change your settings in order to optimize the battery life:

    Maximize the life of the battery and battery life

    Best regards.

  • MacBook Pro display problem

    Hello members of the community.

    As of recently, I have noticed some glitches when feeding on my MacBook or awakened from his sleep.

    The colors are distorted, usually with pink, green, or yellow blobs. Blobs cannot entirely replace the colors, they appear to be contained in a element would normally be. For example. the menu bar will be partially pink and white, but pink does not leave the menu bar in this area, and the Office has green lines on it.

    I tried to take a screenshot, but the problem resolves in about 20 seconds, but it's a recurring problem.

    It happens when I wake up, connection or not. I had also certain powers serious and problems of performance, such that my MagSafe LED would not illuminate when plugged on rare occasions, fan could turn unnecessarily, graphics performance were SUPER slow, and the health of my battery was running out quickly. I actually ran a report on the system at 2 different times and my quality of full load is depleting of 1.2% per charge cycle, which is very worrying. I went from 6281 mAh mAh 6138 maximum capacity after two cycles of load. I'm tracking closely it because at this rate, my battery will survive only at load cycles about 150 instead of the 1000 expected, gives me the idea that this could very well be a bad battery. The computer is also warm to the touch while you sleep, not connected to the power supply. I NAP active but even taking into account should not be hotter my iPhone did the same thing.

    I have reset the SMC, and it solved a couple of problems. The charger works fine now and my performance improved considerably (which made me feel better, either it is a high-performance laptop, a 11-inch MacBook Air should not he surpass), and battery life has improved. I feel even if it uses a lot of power in his sleep. Maybe I need to turn off the NAP and see if that makes a difference. The graphic bug still persists however, and I don't have enough time to see if the max battery is depleting again.

    In regards to the bug, is there something that can be done? Basically, I want to assure you that I took all appropriate measures or if someone else has this problem to see if it can be software related instead of my computer.

    I have the entry level MacBook Pro with the retina, last generation.

    Any constructive contribution welcome!

    See you soon.

    -adreaux

    Hello bernardn753,

    After reviewing your post, it seems that you are having problems with the screen showing strange things on it. Looks like you already have a troubleshooting. I recommend you read this article, as reset NVRAM would be to reset your screen resolution settings that should help.

    How to reset the NVRAM on your Mac.

    Thank you for using communities of Apple Support. Good day.

  • with IOS 10.0.2 - 5s iphone Bluetooth problems

    Since upgrading ISO 10.0.2 my M50 from PLT Plantronics (helmet unique headset) do not reliably connects with my iPhone 5 more. I have to go to the settings, activate bluetooth turned off/turned on, touch the device on the bluetooth page, etc. Once it connects successfully, it will reconnect (if I turn off the headset and turn it back on) for a short period. The next day he does not connect itself but I play with bluetooth on the iPhone again.

    It has always worked perfectly before the 10th of IOS.

    And, as I noticed others mentioning, the volume is much lower with IOS 10. The maximum volume is much lower. I can barely hear it now, more normal background noise, while driving.

    I did:

    Forget this device for the PLT M50 and paired again (several times)

    I did a Reset Network Settings

    I don't know what else to do - but it's a 10.0.2 IOS issue.

    Hello AppleUser2k,

    Please ask questions about your problems of connection between your iPhone and your Plantronics headset since you upgraded to iOS 10. I understand how important it is to have your Bluetooth devices connect with your iPhone with reliability. Here's what I recommend.

    The first thing we want to make sure is that all your data is safe. You can perform a backup in iCloud or iTunes using this article: backing up your iPhone, iPad, and iPod touch.

    Once your data is safe, try the troubleshooting steps in this article to help: get help to connect a Bluetooth accessory with your iPhone, iPad or iPod touch device should also check with the manufacturer that the device has all the drivers and firmware to work with the new version of iOS.

    If you have checked everything and that you have installed the latest firmware or driver and always are problems, please be aware of your surroundings when you encounter these problems. If you can isolate the time or location, you see the problems, you can isolate the cause. You can even see this help article to ensure that you are not affected by outside interference: the potential sources of Wi-Fi and Bluetooth.

    Thanks again and have a great rest of your day.

  • Problem after update 10.0.2 iOS iPhone touchscreen

    After I have updated to iOS 10.0.2, I noticed a problem with the touch screen. Using the position of the image on the right side, near the corner, the toushscreen does not work.
    For example: when you use the keyboard, I can't type the letter 'P', have trouble typing BACKSPACE. Using the Contacts app, I can't scroll through using the alphabet bar.

    Do what idea of the problem?

    Kind regards!

    Hi fabriciorela,

    Thanks for the upgrade to iOS 10! I understand that the right of your screen is unresponsive to the touch. You can try the steps in this link to fix the problem. If the screen of your iPhone, iPad or iPod touch does not respond to touch

    If it does not help the problem, try to restore the device to factory settings. I would like to backup your important data first.

    The backup of your iPhone, iPad and iPod touch

    Use iTunes on your Mac or PC to restore your iPhone, iPad or iPod to factory settings

    Please use the Apple Support communities to post your question. Let us know how it turns out. Have a great day.

  • Bluetooth connection problem iPhone - audio system Nissan after upgrade iOS10

    After iOS10.0.2 iOS9 on iPhone upgrade, I got a cordially problem receive calls raise Nissan car audio.

    I can make a call without any problem. Bluetooth connection is stable. I can download address book e.t.c. But I can't receive a call. I see the incoming call on the radio shows. After pressing the button "answer" on the car Audio System, audio between iPhone and Audio streams car breaks down.

    But the cellular connection remains active. I need to rotate the audio output on the screen of the iPhone car for iPhone and back to the car. After that, I can continue my call via the car radio.

    Thanks in advance

    Hello StasV,

    Thank you for using communities Support from Apple. I know having a problem with calls on your iPhone in your car, it's not what you expect. The good news is that these steps will be useful for your problem of phone calls while using the bluetooth in your car. Go to settings > general > accessibility > routing of Audio calls and the value headset/Bluetooth Headset and retest your question.

    Audio routing call - the iPhone user Guide
    Help to connect your iPhone, iPad or iPod touch with your car radio

    See you soon!

  • 2 iphones on one iTunes, problem of photo icloud account

    OK, my brother-in-law just updated its OS on his Iphone. He shared an Apple ID with his wife, who has his own iPhone. They all have two backup only in iCloud. His problem is that his wife photos are now on his phone. How can he fix it?

    Get its own identifier Apple- create and start using a Apple - Apple Support ID

  • Problem activation ISO 10 September 2016

    After my Ipad iOS 10.0.2 update I could not activate because it says I am not access with the original Apple journal. Makes no sense. I bought the new Ipad in seven of 2013 Dabs.com. She has been linked to my Apple account 10 days ago (I deleted my profile by own Apple support Web site suggestion as a way to fix my problem, the other restoration/upgrade to the Ipad with ITunes update). I contacted the support of Apple (I have two numbers in case Apple). Asked Apple support to provide a proof of purchase I made. Told me now the reception that I provided does not correspond to my Ipad, but Apple isn't going to help with all the details to help to regularize the situation. The Ipad is mine and well was linked to my account from the date of purchase in September of 2013 until I removed it at the suggestion of site specific help from Apple. I now do not have access to my ipad £460 for more than 10 days and have lost money and time talking to 4 different cooperatives of Apple, after 6 calls and none seem able to deal with a ridiculous situation. Alexandre Vitorino (Apple) seems to have the best handle on weird how this situation is. Please can someone fix this? A software update on an Ipad that I own shouldn't stop me using it and then force me to prove that I admit actually before I use it again! I'm a professional businessman who uses it for meetings of the Council. I have a receipt for my camera and get treated like a kind of criminal.

    My sincere sympathy for those who can't find their original receipt or forget their original log-in Ipad because Apple does not help, you and your Ipad will be also useless mine is currently!

    If you are in the same situation please confirm to this post. I can't be alone, if she feels like it!

    Post edited by: cibble10

    Lock activation occurs when the ID of original Apple blocking it does not match with your current Apple ID.

    Until you can bring a receipt valid from an Apple reseller or authorized, it's nothing you can do.

    BTW, the polling stations in this Apple-owned forums is prohibited. You can review the terms of use.

Maybe you are looking for

  • Problem keys NB100 after BIOS upgrade

    Hello After I updated the bios to version 1.60 than some quick keys, such as the brightness setting (fn + f9/f10) or the 'secret' (fn + f6) don't work anymore when the operating system starts, they work rather before loading the operating system. I u

  • Satellite M40 reads no DVD of product recovery

    Hey all. I have a little problem that I hope someone can help me.My laptop Satellite M40 fell while he was in the bag and the dvd player has stopped working. I had repaired it and it plays CD but I can't get the recovery disk to work.It opens, but fo

  • XP Home OEM locked fixation after replacing the motherboard

    I am repairing a HP Pavilion with XP home SP3 locked to the motherboard fried as a favor to a friend.  My friend insists on XP and wants / needs to preserve installed programs & data on the disk (which is always good when tested elsewhere).  He has s

  • whenever I click on a program, that it does not open and the 'open with' screen appears

    whenever I click on a program, that it does not open and the 'open with' screen appears

  • weight light autonomous vs

    I have a remote site that will require about 15 APs. I was wondering if there was a rule when you have to go light autonomous vs. I feel independent would be the answer with this small configuration because this would save money and 15 must be easy t