Parsing JSON to ListView array problem

I need help in parsing JSON to ListView array.

I have no problem to parse this JSON

[
    {
        "id": "123",
        "name": "KFC",
        "contact": {
            "phone": "+1175757",
            "twitter": "kfc"
        }
    }

to this qml:

import bb.cascades 1.0
import bb.data 1.0
Page {
    content: ListView {
        id: listView
        dataModel: dataModel
        listItemComponents: [
            ListItemComponent {
                type: "item"
                Container {
                    verticalAlignment: VerticalAlignment.Center
                    Container {
                        horizontalAlignment: HorizontalAlignment.Fill
                        verticalAlignment: VerticalAlignment.Center
                        layout: DockLayout {

                        }
                        Container {
                            horizontalAlignment: HorizontalAlignment.Fill
                            verticalAlignment: VerticalAlignment.Center
                            topPadding: 20
                            layout: StackLayout {
                                orientation: LayoutOrientation.LeftToRight
                            }
                            Container {
                                verticalAlignment: VerticalAlignment.Center
                                leftMargin: 30
                                Label {
                                    bottomMargin: 0
                                    bottomPadding: 0
                                    text: ListItemData.name
                                    verticalAlignment: VerticalAlignment.Center
                                    textStyle {
                                        base: SystemDefaults.TextStyles.TitleText
                                        fontWeight: FontWeight.Normal
                                    }
                                }
                            }
                        }
                    }
                    Divider {
                    }
                }
            }
        ]
    }
    attachedObjects: [
        GroupDataModel {
            id: dataModel
        },
        DataSource {
            id: dataSource
            source: "myjson.json"
            onDataLoaded: {
                dataModel.insertList(data)
            }
        }
    ]
    onCreationCompleted: {
        dataSource.load();
    }
}

but I do not know how to work with this type of JSON:

{
    "meta": {
        "code": 200
    },
    "response": {
        "myplace": [
            {
                "id": "123",
                "name": "KFC",
                "contact": {
                    "phone": "+1657465",
                    "twitter": "kfc"
                }
            }
        ]
    }
}

can someone help please!

The problem is that DataSource will convert your JSON to a QVariantMap, and not to a QVariantList, as required by the GroupDataModel::insertList ().  Try this:

        DataSource {
            id: dataSource
            source: "myjson.json"
            onDataLoaded: {
                dataModel.insertList(data.response.myplace)
            }
        }

Tags: BlackBerry Developers

Similar Questions

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

  • Difficult to parse JSON

    Hi all

    I tried to analyze the JSON WebService part trati coming here.

    I was able to analyze only the inner part using NEITHER "unflatten of JSON. The main problem are:

    (1) this JSON is an array of objects of different type

    (2) this JSON contains the value without a name

    All tips will be useful, and thanks in advance

    Golzio

    [{
    "name': 'DC Comics."
    "rev":]
    [1389826800000, {}]
    "Note": "Note title 1",
    "Vote':"EVEN. "
    "createdBy": "Batman."
    'timeInMills': 1389826800000,
    'detailNote': ' this a detailed memo.
    }],
    [1391122800000, {}]
    "Note": "Note title 2",
    "Vote':"EVEN. "
    "createdBy": "Superman."
    'timeInMills': 1391122800000,
    'detailNote': ' this a detailed memo.
    }],
    [1392418800000, {}]
    "Note": "Note title 3",
    "Vote':"EVEN. "
    "createdBy": "wonder woman."
    'timeInMills': 1392418800000,
    'detailNote': ' this a detailed memo.
    }]
    ]
    }, {
    "name':"Marvel. "
    "rev":]
    [1388530800000, {}]
    "Note": "Note title 3",
    "Vote':"EVEN. "
    "createdBy": "Spiderman."
    'timeInMills': 1388530800000,
    'detailNote': ' this a detailed memo.
    }]
    ]
    }]

    Hey Golzio.

    The problem here is that the primitive JSON Unflatten only makes it easy to parse the JSON data that are well represented by the types in LabVIEW. For cases like this where we have a mixed array types are more difficult.

    It is possible to parse JSON arrays with which coexist types using LabVIEW primitives. This is done by using path of entry to Unflatten of JSON to navigate the JSON data and extract the values you need.

    The following example shows how you can create paths in order to extract the data from your data set:

    In this example, you can see how we build the table of path in the loops and Unflatten of JSON to retrieve values one by one. One problem with this approach is that we call the JSON Unflatten several times inside a loop so it could fits well for large datasets with thousands of articles. The advantage is not requiring no external dependencies.

    I am pleased that the JSON toolkit i3 worked for you (I've developed this specific tool kit of full disclosure) and it is good to know that there are other options are available such as the most recent JKI JSON Toolkit and the existing LAVA JSON Toolkit for LabVIEW

  • How to create the string of JSON using QVariantMap array?

    Hi all

    How to create sub string of Json using QVariantMap array?

    {
        "Test1": [
            {
                "dataTest1": "0000",
                "dataTest2": 1412,
                "dataTest3": "",
                "dataTest4": "0000",
            }
        ],
        "Test2": {
            "data1": 1412008,
            "data2": "0000",
            "data3": "A",
            "data4": "0000",
        }
    }
    

    Waiting for your answer please reply me as soon as possible.

    JSON array is QVariantList

    JSON object is QVariantMap

    then create a QVariantLsit and insert your QVariantMaps

  • How to parse JSON data using REST POST format

    I was able to create service for REST and the GET operations.

    Using what I know I can pass variables to the Manager but I would like to know if someone can give an overview by creating REST and POST and process json data.

    Thank you

    You can use the following documents to understand how to create GET and POST REST of service operations. There are examples and step by step instructions.

    E - IB: how to create and access a simple REST based Web Services? (Doc ID 1454887.1)

    E - IB: example for PeopleSoft REST provider service (GET/POST methods) (Doc ID 1533318.1)

    In regards to JSON, you can use Documents to represent the message in JSON format. You can also access/parse JSON data using the Document definition.

    Management of Documents in JSON format

    Thank you!

  • Child parsing JSON with datasource and view in listview

    Hi, I use datasource to get json from url data and I want in the listview, but json data have child, so I don't know how to access.

    My data source code here:

    DataSource {
            id: serviceDataSource
            source: "http://services.okezone.com/json/headline"
            type: DataSourceType.Json
            onDataLoaded: {
                serviceDataModel.clear();
                serviceDataModel.insertList(data)
            }
        }
    

    And here my display list code:

    ListView {
              dataModel: serviceDataModel
              listItemComponents: [
    
                   ListItemComponent {
                          type: "news"
                          ServiceDetail {
                                 title: ListItemData.title
                                 pubDate: ListItemData.published
                          }
                   }
              ]
     }
    

    And here is the response from json to this url:

    [
    
    {
    
      "okezone": {
    
         "version": "0.1",
    
         "headline": {
    
            "request": {
    
               "channel": 0,
    
               "start": 0
    
            },
    
            "status": "OK",
    
            "more": {
    
               "offset": 2,
    
               "start": 0,
    
               "total": 2
    
            },
    
            "news": {
    
               "type": "2",
    
               "id": "796135",
    
               "channel": {
    
                  "id": "519",
    
                  "label": "Surabaya"
    
               },
    
               "published": "2013-04-23 13:21:25",
    
               "title": "Gara-Gara UN, Mendikbud Didesak Mundur",
    
               "summary": "Para orangtua murid menilai, Mendikbud, Muhammad Nuh, harus bertanggung jawab di balik kesemerawutan sistem dan pelaksanaan Ujian Nasional.",
    
               "thumbnail": "http://img.okeinfo.net/images-data/content/2013/04/23/519/796135/BkuPxui4gB.jpg",
    
               "url": "http://services.okezone.com/json/detail/2013/04/23/519/796135"
    
            }
    
         }
    
      }
    
    }
    ]
    

    Thanks for your help, I do it in two days and does not work.

    Hello

    Try this code

    import bb.cascades 1.0
    import bb.data 1.0
    
    Page {
        content: Container {
            Label {
                text: "List View with json parsing"
            }
    
            ListView {
                id: listViewDemo
                dataModel: GroupDataModel {
                    grouping: ItemGrouping.None
                }
    
                listItemComponents: [
                    ListItemComponent {
                        type: "listItem"
                        StandardListItem {
                            title: ListItemData.okezone.headline.news["title"]
                        }
                    }
                ]
    
                function itemType(data, indexPath) {
                    return "listItem";
                }
            }
        }
    
        attachedObjects: [
            DataSource {
                id: serviceDataSource
                source: "http://services.okezone.com/json/headline"
                type: DataSourceType.Json
                onDataLoaded: {
                    listViewDemo.dataModel.clear();
                    listViewDemo.dataModel.insertList(data)
                }
            }
        ]
    
        onCreationCompleted: {
            serviceDataSource.load();
        }
    }
    

    Don't forget to add the library to .pro file

    LIBS +=-lbbdata

  • Parsing XML Array problem

    my previous issue became somewhat a different problem;
    basically now when I trace the variables I'm getting undefined. Any help is very appreciated. Thank you!


    > = award.secondChild.nodeValue description

    There is no such thing as secondChild.

    > image = new Array (images.length);

    Where image is defined at the outset? You can't just use an index like this if
    image is not already an array.

    I suggest you change the design a bit. An array of objects of price
    could work well.

    var allAwards = new Array();

    var price = new Object();
    Award.Caption = "my caption";
    Award.images = new Array();

    allAwards.push (award);

    Then you can do like:

    trace(allAwards[0].) Caption);

    --
    Dave-
    www.offroadfire.com
    Developer leader
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.Adobe.com/communities/experts/

  • 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:

  • Parsing XHTML and byte array size limit

    Hello

    I would like to analyze incoming e-mails on the device to retrieve information. The email format is XHTML and I use a sax parser to extract data (API version 4.2.1).

    InputStream is = new ByteArrayInputStream(xhtml.getBytes(encoding));
    _document = docBuilder.parse(is);
    

    It works fine, but it seems there is a limit of size on arrays of bytes (max count = 1999) because I had an "unexpected end of file exception" when my string is too long.

    Does anyone know how to overcome this size limit?

    Kind regards

    Stone

    By default, I think that just the first 2K of a value of data associated with an email is delivered to the device.  You need to ask for more to get the rest, I think.  Could it be the problem?  Take a look in the knowledge base for articles on this subject, I do not remember having seen that addressed this and describes how to get the remaining data.

  • How to handle parsing JSON with Java for String and String []?

    I have a string of JSON (sample) as follows and I created a POJO Mapper using Jackson to manage the same, but as I saw the data I noticed the problem mentioned

    How should I treat the underside of change of the data of String() string in my class Mapper POJO of ideas would be helpful

    < code >

    @JsonIgnoreProperties(ignoreUnknown = true)
    public class Ref implements Serializable {
    
    @JsonProperty("BBT")
      private String BBT;
    
    .... more code here
    
    
    
    //Sample 1
    "Ref": {
          "ISN": "AEBDC44",
          "CCD": "213128908338",
          "BGID": "XCAS3213213",
          "BBS": "23123123",
          "BBT": "CCC",
          "WRT": "POP91230",
          "SDL": "290123",
          "BUN": "ZZRET10PV4",
          "BCSP": "ZZRET10PV4",
          "CSP": "ZZRET10PV4"
        }
    
    //Sample 2
    "Ref": {
          "ISN": "AEBDC44",
          "CCD": "213128908338",
          "BGID": "XCAS3213213",
          "BBS": "23123123",
          "BBT": ["CCC","AAA"],         //Sometimes recevied as an String array instead of String
          "WRT": "POP91230",
          "SDL": "290123",
          "BUN": "ZZRET10PV4",
          "BCSP": "ZZRET10PV4",
          "CSP": "ZZRET10PV4"
        }
    

    < code >

    Found the solution.

    Thank you seems in any case this forum is not very active over after stackoverflow etc. dominating the WRT forums programming and all

    In the case of some1 should

    Change return type

    Converted to object.

  • Ugh... Requirement: A TimerTask making an HTTP call, parsing JSON, insertion into a SQLite database.

    How to implement a better design of the following?

    I have a UiApplication which has the following requirements:

    1. A static timer in the class that extends UiApplication.
    2. A class that extends screen and contains a class internal which extends TimerTask.
    3. When a user accesses to the screen, the TimerTask is started with:
      _timer.schedule(MyTimerTask, 1000, 15000);
      
    4. The first step is to do an HTTP call and return a valid JSON object which varies in structure - that is, it has a wide variety of paintings and JSON objects.
    5. The second step is to analyze and insert the JSON object values into tables in a SQLite database. The SQLite file is on the map.
    6. The third step is to read the updated SQLite table, loop through the table and build my ObjectListFields with the new values, and attach them to a VerticalFieldManager.
    7. The fourth step is to replace the old VerticalFieldManager with the new VerticalFieldManager and push the screen pop and updated then the current screen - so I have a stack of view high one single layer.

    Now the logic is actually on the spot, but since the TimerTask must cover every 15 seconds, I am a memory leak in all directions.

    To try to solve this problem, I have:

    • Cancelled the TimerTask with the onObscured and the onUiEngineAttached (false).
    • Restart the TimerTask with onExposed and onUiEngineAttached (true).
    • My DatabaseConnection closed the finally statement.

    However, when I look at the objects in Eclipse BlackBerry objects View when the TimerTask is not running, I still see 1 ~ 4 TimerTask objects and 1 ~ 4 DatabaseConnection objects.

    TimerTask both DatabaseConnection have a static instance (I don't have several entry points) with the following in my class that extends UiApplication:

    public static Timer _timer = new Timer();
    public static Database db = null;
    

    I attribute db when I need it with a call to DatabaseFactory.open within the class that extends TimerTask.

    Now that the business logic is correct, how to improve the design so I don't not leaking memory in every way?

    The statement closed the database is being called in, because I can set a breakpoint and see it has reached.

    Instead of onObscured/etc, you can move them into onVisibilityChange (boolean) is only in one place. Cancel your existing TimerTask before running a new, or at least check the TimerTask reference if you are only creating a... not just passing 'New TimerTask' in the calendar method without being able to track this object reference.

  • ListView / sheet problem - not selected item after the opening of leaf.

    Hello

    In my main.qml, I have a listview using the standardlistitem.

    I have a popup menu attached to the standardlistitems.

    Now, initially, I had a problem of selection of a list item when I called one of the options in the context menu of the element. The element does not get selected when you make the menu appear.

    To solve this, I use the onTriggered signal from the context menu to call select on the listview. He calls the onSelectionChanged listView itself signal.

    Now here is my problem:

    If I call a function c ++ this signal of the main.qml and in this c function onSelectionChanged ++ I call the funtion selected() on ListView to obtain the row function works correctly and the index is returned.

    But if I have everything first to make a visible sheet and call the function c ++ within the call to selected() worksheet returns nothing.

    There is nothing in my qml or CPP which clears the selection, this occurs by default or something when the worksheet is opened?

    THX.

    This answer worked for you?

    Graham

  • How to parse json

    Hello, I have different types of json please guide me how to analyze this type of json. It is having json object.

    [
    {
    content: " ",
    title: "Bhagwan Shri Sathya Sai Baba blessed the manuscript of the book on 2nd January 2011 at Prashanti Nilayam, Puttaparthi, Andhra Pradesh",
    div: "div4",
    imgsection: "0",
    textsection: "0",
    images: [
    "31aug_4.jpg"
    ]
    },
    {
    content: " ",
    title: "Presenting the book to the senior members of the party on 30th August 2013 at the BJP party office, New Delhi",
    div: "div4",
    imgsection: "0",
    textsection: "0",
    images: [
    "31aug_6ShriRajnathSinghji.jpg",
    "31aug_8ShriRamLalJi.jpg",
    "31aug_7AartiMehra.jpg",
    "31aug_9MahinderPandey.jpg",
    "31aug_10OmprakashDhankarji.jpg"
    ]
    },
    {
    content: " ",
    title: "A picture of the foreword of the book, written by Shri Nitin Gatkari",
    div: "div4",
    imgsection: "0",
    textsection: "0",
    images: [
    "1 sep_4.jpg"
    ]
    },
    {
    content: " ",
    title: "Various Newspapers reporting about the book release.",
    div: "div4",
    imgsection: "0",
    textsection: "0",
    images: [
    "1 sep_5.jpg",
    "1 sep_6.jpg",
    "1 sep_7.jpg",
    "1 sep_8.jpg",
    "1 sep_9.jpg",
    "1 sep_10.jpg",
    "1 sep_11.jpg",
    "1 sep_12.jpg"
    ]
    }
    ]
    

    If it is a use table JSONArray. If it's an object use the JSONObject.
    Identify the model?

  • Size of array problem in Windows 7

    Hi all

    I have a VI through the opening in a new laptop, it shows a few tables inadequate controls (with a table diferent size), however I can´t put it right.

    But when I'm doing an EXE of this VI and if I run the EXE in another computer, the façade seems aligned and Ok.

    I m using the labview 2009 Sp1 with Windows 7, this vi have been created in another laptop in an older version and always with the Windows Xp, and every time that I updated the version of labview always seems correct on the laptop, until now when I changed the laptop computer and the operating system to Win7.

    Any help/advice is much apreciated

    Thank you

    Make sure that you use the same font settings for all the controls you want to align. You might have some controls set a specific font name and others left the police to default Application. LabVIEW replaces the police request regardless of the default font of the system is on a particular computer.

    Different fonts are by default and available on different versions of Windows then you can definitely get in trouble here if you mix families of fonts and the names in the same user interface.

    If you request a specific font name and it is not available on some Windows machine will be replaced by another policy that he thinks looks like but the heuristics of this substitution can sometimes go really South of the Ecuador and just give the crazy results.

  • File CSV Array problem

    I was faced with a csv file import and the creation of a table. I am able to have the file to display in a dynamic text box with commas, but may not understand how to use commas to separate data in grids.

    If anyone can help it would be much appreciated. I have two weeks to complete this and have spent countless hours of research a solution. Thank you in advance.

    My current code is:

    var loader: URLLoader = new URLLoader();

    Loader.Load (new URLRequest ("external.csv"));

    loader.addEventListener (Event.COMPLETE, onComplete);

    function onComplete(event:Event):void

    {

    external_txt. Text = event.target.data;

    }

    The comma-delimited file is "external.csv" and the name of the dynamic text field 'external_txt '.

    Thanks again

    Just use the split() the String class method to csv text in a table.

Maybe you are looking for