QVariantMap to QVariant to JSON string

Hello

I want to convert QVariantMap or QVariant to string in JSON format.

Please some Walter tell me how?

http://developer.BlackBerry.com/native/reference/Cascades/bb__data__jsondataaccess.html#function-sav...

Tags: BlackBerry Developers

Similar Questions

  • To Webservice JSON string validation

    Hi, I am a beginner, Blackberry developer and I would like help JSON string to a report Web service. I currently have the php pages that accept data in JSON format. Is there a way to do this? Any help would be appreciated. Thank you.

    Hello

    > showing the JSON string to a webservice

    give this to start reading:

    http://supportforums.BlackBerry.com/T5/Cascades-development-knowledge/using-XMLHttpRequest-from-QML-...

    g

  • BlackBerry how to parse date in a Json string...

    I have the server time in Json String.is there no Json deserializer for what there so I have time.
    If not pls suggest how I can analyze.

    "StartTime": "\/Date (1349818680000 + 0530) '--------/ '"

    Consider the time manually.

  • Image data that is embedded within a JSON string.

    Hi all!

    I would put the image data 'sequenced' in a JSON string so that I can use in ScriptUI, pick from a JSON object.

    An example is the following:

    'image' : ' \u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00F\x00\x00\x00\x1E\b\x02\x00\x00\x00\x1E\ u0091\u00FFI\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e < \x00\x00\x03\u0099IDATx\u00DA\u00EC\u0098\u00CDK\x14a\x1C\u00C7\u009DZ \u00EC\u00D0\u00AE\x07\x13\u00D4\u00C4\u00C2\u0097\u00D8,\u00D8\x12\u0094\u00A0\b\u00A2 \n\x02o\u00DD. [[: t\u00EC\u00D6\u00BDK\u00E7\u00AE] \x14,\u0083PR\u00935S \u00FA\x03\u00BAu\bO\u0082\u0081\u0087\u00 C4!] h\u00D7C\u00B3\u0097 > \u00E3\u00D7~ > \u00CC\u00AC\u00B3\u00B9\u00BB\ u00A2\u00C8 > \f\x0F\u00CF < \u00FB{\x7F\u009F\u00F5\u00DE\u008F\u00CE4\x1C\u00AFu\u00A2\u00E1 \u00D8\u00AD\u00BAJu\u0095\u008E\u008AJk\u00EB?\u00E7\x17\u00E6\u008E\u009B\u0097\n[\u00F9 Z1\u00C0@\u009Ff\u00A6\u00D8c'\x00\u00D8/\u00D9\x18\u0094DT\u0082o\x0B\u00B3\u0086\u00B6\u 00BA\u00B6\u00D2\u00DE\u00D6\u00A1\u00D7\u00E4\u00E9T [\u00EB\u00D9\u00F9\u00C5\x1D\x07^\u0 0CD\f\ u0084\u00A8\u00F7v\u00A7\u0093\u00C9\u0094\u00CE\u00F8Yv\u0081Z\x7Ff\u0090\u00BDP\u0 0C8\u009B\u00A5\f\u00D7\u00E5\b\u00FD\u00DE\u009E\u00B4K\u00D0n\u00C0\x15_ndq\u00A1\u00B8\ x1Cm\u009D|\u00FC\u00E8\u0089\u00FB\x0E\u00C4\u00F9\u00CE\u00AE\\n\x03\u00E9y.\u00F4\\\x1C \u00FF0v\u00E7\u00D6=\u00CE~\u00D1\u00FF85q\u00F3\u00FAm\u00CE\u0090\u00CE./57\u00B7Hm]~\u 009D\u00FD\u00C2.:\ u00D9\x1FK\u00C8\u00CD\u00EB\u0099\u00E6\x16\u00DF\u00F7\u00A13 = 3\x19\u 00C25\u008E\u00C5\u00A2\x0F\u00B0n \b\u00C0\u00A5\u00BE\u008C8\"=\x00P\x165n6s\x1B\u009C\u0085\u00D2\u00D8x\u00AA\u0092\u00F 2\u00804:@q\u00D7c\u00C9\u0094L\x0E{\u00D9\u00C9u/+_\u00F8m\u0096f\u00C7.\u00E8\x13\u00C2-\u00B9 \"\u00CF\u0088\u00A3\"\u00D6\u00A8\u00C9\"\u00F1\x02'\u00AAL\x15\u00E4Km5aZ\u00B9T\u0097 (@\u00A8\u00B0\u00A7\u0092M\n\u00B3\u00D5\u00F5\x15\u008BX\u00D3\u00B3D\x0E\x17\u00F2\u00FC) ' u00E4\u00E6\u0089\u00DC\u00AE'\x11\u0080\u0099f\x07 > \x12x\u0089\u00EA\u00B3\u00DF\x12C^\ ' \u008B\u00D0\u0084\u00FCq\u0099q\u00E3\u00E6\u00CF^\u00C9\u008D\u00DA\x04B\bR\u00BE2M\\\u0 087\x03\u00EF\x02\u00C7\x05\x1E\u00E9af0\u00A7\u00EFu6\u00DD\x14$ \x04\x15? \u00C1\x18i\u00E C! \u008FM\u008Dh\u0087\u00B0\x00\u0093\x03\u00ED\f\x11yi\u00FA\u00F3\u00A4\u00F1mo\u00ED\u 0088\u00B7\u00B2\x17\x1A[\u00AD\u00B6\u00B8\u009C\u00940%\u00CF\u00C4\u00BDdU\u0094\u0083\ u008B\u00F4!\u00E3\u0089\u00A6\u00EE\x05iUd\u00D7?\u00DB\x15RXf\x1D+hv\x13\u00AA\u0081%Iy\ x071\u0089\u008F\u008C\x0E\u00DF\u00BF; d\u00AF\x18; \x14\u0087\x07\u00BA\u00CA\u00AB$\x0B\u 0099y*h\u0085%\u00BB\u00C7\u00A1\u00CDxA\x7F (, \x04\u00F1\u00F0\u00F2\u00D5\u008B}\u00D1\x05 \u00C5\u009E\u00FF\u00D7\u00E7\u00D9\u00F3\u00A7e\u00ED[\u0095\u0097\u00E4\x1Fl\x1C\u00EC= \u00E9P\u00F8\u00CAu\u00AA\x07\u00FC\x14\u00F5\u00A1\u00CA@\u0090c\u00FFT2\u0082\u0096\u00 8D\ u00C18\u00B20\u00C7\u00AB\u00E5\u00AD\x11\u00D7Y\u009DW\u00DCU\u00E2\u00CA\u00C6K\u009C \u0097\u00A0H]\u0096\x1A\u00F0\u00A0\u00FD+}\u00DF\u00BC}\u00BD#\u00CD\u00E2\u00DC\u00C8\u 00BBa\u00E3\x1D\n <) /'%\u0098\u00BC\u00A7\u00B1\x18\u00C9T\x15\u00A5CP\ x1E\u00B6 [\u0099) {\u0 0CF\x19\\\u00F4\x07\u0080\u00B3\u00AC\u0080 < \u00D1zPf \n-\u009B;\u0090\u00FE\u00DA\u00C0\r\u009B\u00984\u00FB\u00F0l\u00E6~]\u00EE\u00CB\u00F0\ n3\x0E\u00AE\u0087\u00CFuv\u0081\u00E8y\u009E\\\u00C1\ u00AF\x1Ay\u0098\u00AA\u00FC\u00E2\x 1F\u00BA' \u00C4\u00E51$ \u00E6\u00A6\u00FF\u00CA 7\u0092\u0098 = \u00BB\u00FC} \u00E8\u00C1C (\u00F0\u00C0\x11\u00E5\u0099\u0092\x00\u0080l\u0 0ED\u00A7\u0087P\x0F\u0095\x04\b\x17\u00AD {\u00F4M\u0089\] u00A8Q\u00CD, \u00B3\u00B4.\u00B9 \u0089\u00C6\u0092\r_\u0087\u00F3\t\u00E8 & \u008C\u00A2\x0E\u00DFR\u00C7\u00D9\u00E9\u0092\ u00A1\u009C\u008EJ\u00BF\u00AFZZ\u00B2YW\u00AB\x12\ "\u0096\rhe3\u008B\u00E1\u0085\u00B3;\x 1F (\u00CB\u00CBr\u00B1\t & \u00CA1\u00FEs.\x11o\f2\u0084\u00E9 & \b\u008C\u00EE\u00B4\u008D\u0 0A1\u0096\u00E5\u00FC\u00BAW\u00CBr\u0085VQq? \x04\u0083I\u00C2! n\x15\u00C2\u00BD! \u00F0\u0 0A2\x1FN\u00F6\u00F5QU\u00AB = \u00AC\u00A5\u00E8\u00AD\x001qd\u00F5\x19\u009F\x18\u00ABl\u0 0F2\u00F0\u00EA\u00FF\u00B6\u00D6U\u00AA\u00ABT\u0093\u00F5W\u0080\x01\x00H@\u00A4W\u009F\ u008F\u00E9\u009D\x00\x00\x00\x00IEND\u00AEB'\u0082 " "

    As you can see, this site did not like all the stuff that are highlighted in red

    https://jsonformatter.curiousconcept.com/

    Parsing JSON was not working in the analysis of these data, and of course this image did not show in my ScriptUI dialog box.

    Any suggestions on how to format it to conform to the JSON syntax, if possible?

    Thanks Micky, it seemed that avoidance by means you listed had somehow changed some real characters, so it does not end up practicing in real code. However, I also noticed that the site I listed myself was less than optimal for understanding my problem: I used instead (http://codebeautify.org/jsonvalidate), I would have quickly noticed the blackslashes issue because it uses better syntax highlighting!

    Now, I decided to use encodeURI() to transform this channel of image data in a valid JSON string. It seems to work when you turn such a string directly in a ScriptUI.newImage (), but now I have to find one couple of other things to make sure he got by JSON analysis inside my script, I'm working on that.

  • Convert string (JSON string) JSON object?

    * EDIT *.

    I finally understand how to use #include instead of file.read (); This solves my immediate problem. However, I am always curious to know if it is possible to do what I request below, just in case there is a situation where for some reason any I can not just use #include. Thank you all. =)

    * EDIT *.

    * EDIT 2 *.

    Someone knows how to use #include for a file whose name is determined during execution of the script?

    For example... the orderNumber variable is generated by a window (lets say that the result is 1234567). the file I want to include will be called "1234567.js).

    What I want to do, it is something like:

    #include ' ~/Desktop/Info folder / "orderNumber + '.js '.

    (then I want to assign a variable the result somehow, since it is simply an anonymous object at this stage and I don't know how to access its content);

    * EDIT 2 *.

    Hey all. I have a (probably stupid) question about how to take a string that contains the JSON text and simply modify this type of 'chain' to 'object '... I'm wording probably this very badly.

    I get a file .js on my local network and by assigning a variable the result of file.read ();

    The content of the file is an anonymous object in JSON. However, when I use the file.read (); the object is placed in the string, like this:

    "{"Alignment": [{'name': 'Fink', 'number': '19', 'jerseySize': 'XL', 'quantity': '1',"topId": '78531'}, {thi s is the next player}, {it is the next player}]}"

    It's a massively simplified version of what I read actually, but you get the point. I want to put this object in the script that I'm running and create new objects based on the relevant information (in this case I need only the values for 'name', 'number' and 'jerseySize').

    So my question is this. How can I activate the above JSON string into:

    alignment of var =]

    {

    "name':"Fink. "

    «number»: "19.»

    {"jerseySize": "XL"},

    {

    next player

    },

    {

    next player

    }

    ]

    ???? A google search reveals the JSON.parse (text) method. But that is not supported in ESTK.

    for simple objects, as in the example, you could use eval() hurt, get rid of the 'alignment' first

    var str = "[{'name': 'Fink', 'number': '19', 'jerseySize': 'XL', 'quantity': '1',"topId": '78531'}, {'name': 'Fink', 'number': '19', 'jerseySize': 'XL', 'quantity': '1',"topId": '78531'}] '"

    alignment of var = eval (str);

    $.writeln(roster[0].number);

  • Adding a JSON string to a RESTful outgoing call in OSB 11.1.1.6

    Inside of my stream of messages of the Service Proxy (OSB 11.1.1.6), I have generated a JSON string and stored in a variable named $jsonReq.

    In my action of routing, I point to a Business Service that the Service Type is 'Messaging Service' with both Types of request/response as "Text" messages

    What is the right way to attribute the $jsonReq content of the variable for the body of the outgoing request (I'm making a POST)?

    I tried a number of configurations, but not prevail (although I see the content JSON when I throw out in a Log action), such as:

    Insert
    Expression: $jsonReq
    Location: as the first child of the
    XPath:.
    In Variable: coming out


    Please notify.

    Thank you
    Michael

    Use replace. / * in the variable body with $jsonReq choose replace entire node.

  • The small JSON string loading

    This is probably a stupid question, but I'll ask it anyway.

    I have a class of datamodel who comes into contact with a web service and then recovers the JSON data. There is one case where I don't want JSON service but only a code. This code, I want to load a single line of JSON data. How to declare the JSON data to a local string instead of demand response?

    QVariantList m_jsonData;

    m_jsonData = jda.loadFromBuffer (buffer);

    JSON data '[{\"type\":\"99\",\"datesort\":\"\'}]".

    Thank you. Has got a brain lock this morning.

    @Zmey,

    It is declared as

    QVariantList m_jsonData;

    I changed the code of

    m_jsonData = jda.loadFromBuffer (buffer) .toList ();

    and everything worked. Thanks for the help and for having me on my brain freeze.

  • Array of bytes in JSON string is not a valid JSONObject.

    I get an array of bytes from a URL that I can view in Google Chrome as a valid JSON object.

    When I get the answer to IOUtilities.streamToBytes (), it returns in the following way:

    [16, 8, 1, 10, 2,... 1, 0, 0, 8, 0, 0, 120, 2, 0]
    

    How can I convert the byte array to a human readable string I can spend in the JSONObject constructor?

    I tried the following character encodings:

    • "ISO-8859-1".
    • 'UTF-8 '.
    • "UTF-16BE".
    • "US-ASCII".

    Hello

    First, check with your http connection that it returns the appropriate response.

               connection=(HttpConnection)Connector.open(url,Connector.READ);
                connection.setRequestMethod(HttpConnection.GET);
                if(connection.getResponseCode()==HttpConnection.HTTP_OK)
                {
                    inputstream=connection.openInputStream();
                    int ch;
                    buffer=new StringBuffer();
                    while((ch=inputstream.read())!=-1)
                    {
                        buffer.append((char)ch);
                    }
                    System.out.println(buffer.toString());
                }
    

    If so, you need to spend just that data in json for parsing.i

    Thankx

  • How to extract string in JSON data where the value in a table

    Hello

    Structure of JSON string

    {'name': 'John', 'name': 'kumar', 'address': [{'Address1': 'value', 'place': 'value'}, {'address2': 'value', 'place': 'value'}]}

     


    How to extract the value of the address of the list.

    If you have control over the format of data, it is best to rename address1 and address2 to have the same name, for example "address". Then, it can be analyzed that way (I've also simplified other code a bit):

    JsonDataAccess jda;
    QVariant v = jda.loadFromBuffer(jsonString);
    QVariantMap m = v.toMap();
    QString name = m["name"].toString();
    QString surname = m["surname"].toString();
    QVariantList addresses = m["address"].toList();
    foreach (QVariant addr, addresses)
    {  QVariantMap addrMap = addr.toMap();
      QString addressValue = addrMap["address"].toString();
      QString place = addrMap["place"].toString();
    }
    
  • How to replace the string "\" on json webservice?

    Hello

    I have problem with this json

    "{\"search_result\":[{\"name\":\"Mall Summarecon\",\"category\":\"BusinessEntity\",\"id\":\"1\"},{\"name\":\"Bamboo Dim Sum\",\"category\":\"BusinessEntity\",\"id\":\"2\"},{\"name\":\"Dimsum Ceker\",\"category\":\"Item\",\"id\":\"1\"}]}"
    

    I want to replace the string "\".

    the json are already working on my app via .cpp file

    I already add json.replace on my qml

    function simpleSearch(response){
            indicator.stop()
            model.clear()
            console.log("Response: "+response)
            var json = JSON.parse(response)
            json = json.replace('\\', ' ') // this is how the way i replace
            if (json == "[]")
                notFound.visible = true
    
            else
                model.append(json.search_result)
        }
    

    but still does not work

    is there a different way to replace it?

    Thank you

    Change your simpleSearchFinished as follows

    ....simpleSearchFinished()
    {
        QNetworkReply *reply = qobject_cast(sender());
        if (!reply->error()){
            QByteArray response = reply->readAll();
            response.replace("\\", "");
            if (response.startsWith("\"")){
                response.remove(0, 1);
            }
            if (response.endsWith("\"")){
                response.remove(response.length()-1, 1);
            }
            emit simpleSearchDone(response);
        }else{
            const int httpCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            qDebug() << "ErrorCode" << httpCode << endl << \
                    "ErrorString" << reply->errorString();
            emit error(httpCode, reply->errorString());
        }
        reply->deleteLater();
        manager->deleteLater();
    }
    

    and QML

    function simpleSearch(response){
        indicator.stop()
        model.clear()
        var json = JSON.parse(response)
        if (json){ // is VALID/PARSED
            model.append(json.search_result)
        }
    }
    

    As I wrote, it is not a good workaround solution. The best is to send VALID JSON string directly from your server. But it works

  • How to record a little complex data in json?

    Hi all

    I want to use json to store complex data a bit. I checked the sample application code. It's too simple.

    The data are as follows:

    {

    'day': 'ddd ',.

    'type': 'xxx ',.

    'name': "qqq"

    "amandine":]

    {'name': 'sss', 'set': 'ddd', 'time': 'ddd'},

    {'name': 'eee', 'set': 'fff', 'time': 'fff'},

    {'name': 'qqq', 'set': 'ggg', 'time': 'ggg'},

    {'name': 'aaa', 'set': 'vvv', 'time': 'vvv'},

    {'name': 'zzz', 'set': 'ccc', 'time': "ccc"}

    ]

    }

    I am confused with QVaraintMap, QVariantList and QVariant and don't know how to use them properly.

    PS: I'm new to json. I used to use MySQL in my work.

    Thank you.

    brad_qqq

    The simplest approach is the following:

    JSON object (something wrapped in {}) will be a QVariantMap

    List of JSON (something wrapped in []) will be a QVariantList

    Everything else (numbers, strings, boolean, etc.) will be a QVariant

    Everything will be a QVariant when initially mapped out, and you must check the types with canConvert (Type) and use the methods toXXXX, that all return values (http://qt-project.org/doc/qt-4.8/qvariant.html) to get the respective types and use the data.

  • on json by http

    Sorry, new developer to waterfall

    is there any document on via http access json data?

    I found a few cpp files when creating extensions webworks but do not know how to use it.

    Thank you

    You can use the class JsonDataAccess, QVariantList, QVariantMap, QVariant access JSON file structure: https://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/working_w...

    Once you set your JSON to QVariantList, there are a lot of discussions in this forum who have excellent explanations on how to access the child elements and properties.

  • Analysis of C++ JSON

    Given the following JSON

    [
    { "id":1, "firstname": "Mike", "lastname": "Chepesky", "title": "Sr. Editor",
      "image": "images/data/mike_chepesky.png", "active": true, "gender": "m" },
    { "id":2, "firstname": "Westlee", "lastname": "Barichak", "title": "Talent Scout",
      "image": "images/data/westlee_barichak.png", "active": true, "gender": "m" },
    ...
    ]
    

    What would be the code to get and set names and surnames like QString?

    I guess JsonDataAccess will be used, but I don't know how to use it.

    Hello!

    This thread contains a code example:

    http://supportforums.BlackBerry.com/T5/native-development/how-to-extract-data-from-JSON-string-where...

    A catch of he: JsonDataAccess returns QVariantList if there are several elements of higher level, but QVariantMap otherwise. If you work with lists, this should be explicitly verified. upd: nevermind, I confused JsonDataAccess with XmlDataAccess where this problem is present.

    To save the new drive:

    jda.save(anyMapOrListWhichCanBeWrappedInQVariant, filename);
    
  • Saving the JSON files with Notepad in UTF-8 format causes error in Unflatten of JSON VI

    After doing a flatten to JSON and write in the text file, I open the file in Notepad and edited one of the fields. Then I registered under and marked 'UTF-8 '. The function JSON Unflatten fails with the 375003 error "the JSON string is not valid. The JSON strings must be encoded in UTF - 8 and must conform to the JSON grammar.

    I did change the numerical value in the field. Does Notepad save not a 'real' UTF-8 file? Someone else had this problem? Which makes it pretty hard to let users to change if the software cannot read it.

    Notepad adds a BOM header said at the beginning of the text file. This indicates a conscious drive UTF UTF type so boutien multibyte UTF encodings (e.g. UTF-16, UTF-16BE, UTF-32). Unfortuntaly notebook is so 'smart' to do it seamlessly and without any notification.

    If you use Notepad ++, or any other smarter text editor, you can avoid this problem of having this BOM autmagically added to the file to save.

    Basically, UTF - 8, you get three codes hexadecimal 0xEF, 0xBB, 0xBF at the start of the file. You can read the file yourself and check these three characters in this order and remove them if they exiist, before passing the string to your string in JSON format Unflatten and everything should be good.

    See here for more details on the UTF BOM.

  • JSON Parser file path not found

    So I have a JSON file from which I am trying to retrieve data, but I can't get the correct path of the file. I use Unflatten of JSON

    The JSON string looks like this:

    {"latitude":32.78,"longitude":-96.81,"timezone":"America/Chicago","offset":-5,"currently":{"time":1478744444, "summary":"Mostly cloudy"},"minutely":{},"hourly":{"summary":"Rain","icon":"rain","data":[{"time":1478744555,"summary":"Cloudy","temperature":60.55,"windSpeed":14.5}{"time":1478745555,"summary":"Mildly cloudy","temperature":60.00,"windSpeed":13.5}]},"daily":{},"flags":{}}
    

    There is much more in the actual string, but the important part is the hourly data, which are divided into 48 different pieces for 48 hours. I know I can get the 'time' and 'summary' part 'currently', but whenever I try to get something 'all hours' or ' schedule / data "I get this error:" LabVIEW: the path is not found in the JSON string. "

    I can get the info 'currently' like this: it is just to show that the path is very simple, just "currently / hour ' and it works.

    But trying to do the same thing does not work with the array of objects:

    I also tried to make the type and by default is the same as what is in the elements of the array 'features', but the error is still the same.

    So is it possible to separate each of the time slices in the 'data', or to extract what is in the block of 'time' and then use the function JSON Unflatten on it again?

    You must include the array index in your path. The hooks in the json data indicate a table, to do something like the following:

    For some reason, I'm getting a "LabVIEW: the JSON string is not valid." Error in JSON strings must be encoded in UTF - 8 and must conform to the JSON grammar. ", but that might just be because of her copy + paste of the JSON string.

    Oh... missing the comma between the elements of the array. Add a comma after the wind speed':14.5} at the end of the 6th line.

    In your second example, you should have the cluster in an array of clusters containing 3 digital items - while must have worked. It takes a little getting used to understand how to convert JSON structures clustered LV.

Maybe you are looking for

  • Update of El Capitan 10.11.4 stop 125 MB download?

    I'm having this weird problem trying to upgrade to 10.11.4. No matter what I do, it stops downloading 125 MB then goes back to the button "Update", as if nothing happened. If I hit the button to update again, it does the same thing. If I try to updat

  • error message on a key recovery

    Hello I have lenovo ideapad G510 and I get an error message when I try to backup my system. the message is "current system cannot support backup. why it does not work?

  • Laptop HP 15: Skyrim on celeron

    Hello, I would like to know if I can play skyrim on my laptop with 4 GB of ram and a processor celeron with hd graphics of Intel (r). Also, I would like to know what year I am able to play games. Thanks in advance for the help.

  • Control of 6500

    I have a 6500 a purchased in 2011 and just connect to a NEW HP Pavilion Desktop all-in-one computer. With my old computer I could click on the dessktop icon and get a 'control panel' where I could check the ink levels, command to scan etc. I can't no

  • Can I sell the models I do with fuse to third parties?

    Can I make new clothes to models of fuse and sell characters with my clothes to a third party?