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

Tags: NI Software

Similar Questions

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

  • 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

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

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

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

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

  • JSON Parser very slow

    Hi all

    I use the parser JSON to parse a long string, stored in a text file. The string is a list of cities in the United Kingdom (about 1300 cities). There are approximately 47000 characters. It takes about 10 seconds on a blackberry bold 9700 to create a JSONObject to the chain.

    You guys have any suggestions to improve performance?

    Thank you

    probably not. You can use a thread with min_priority to keep the head etc. UI, but otherwise, you will take your time, or switch to a more efficient like sqllite or similar data model.

  • Support for the development of the Playbook JSON

    Hello.

    Tablet OS SDK for Adobe AIR does support the analysis of an API in JSON? We can parse JSON in playbook in other words.

    Thanks in advance

    Although I do not know there are third-party libraries you might find with Google, I'll just note here that AIR 3 includes the JSON class as one of the API high level.

    http://help.Adobe.com/en_US/FlashPlatform/reference/ActionScript/3/JSON.html

    Let's get AIR 3 as part of the upcoming 2.0 version, I think this support for this building is probably your best option.

    Edit: Note also that this is done apparently with native code, it should be much faster than any existing third-party libraries, you can find.

  • JSON results in error

    I am currently getting my web service json data, this part is a success, it works perfectly.

    Secondly, I run this code to process the JSON.

    JSONArray arr = new JSONArray (jsonList);
    for (int i = 0, len1 = arr.length (); i < len1;=""> ) { }
    JSONObject obj = arr.getJSONObject (i);
    RichTextField showJson = new RichTextField ("username:" + obj.getString ("Username"));
    Add (showJson);
    Add (new RichTextField("---"));
    }

    But I get an error

    But when I comment on:

    JSONObject obj = arr.getJSONObject (i);
    RichTextField showJson = new RichTextField ("username:" + obj.getString ("Username"));

    Then it works perfectly through each record in the JSON.

    But then of course only displays this

    Add (new RichTextField("---"));

    4 times, as long as there is in the JSON

    Did someone knows why, I get the ERROR when I view the JSON records.

    I got the code for the thread, where they claim it works.

    http://supportforums.BlackBerry.com/T5/Java-development/parse-JSON/TD-p/1314943

    Yes the built in one.

    But I got it to work! Whoo Hoo!

    I change this code:

    RichTextField showJson = new RichTextField ("username:" + obj.getString ("Username"));

    TO:

    StringBuffer buildBubbles = new StringBuffer () .append (obj.getString ("Username"));

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

  • A simple example of filling the data from Json to a ListView.

    I want a simple example to inflate a listview with Json data.

    Examples of the sample do not work

    as we have a code example

    App.cpp

    App::App()
    {
        Page *root = new Page;
        ListView *listView = new ListView;
    
        // Create the data model, specifying sorting keys of "firstName" and "lastName"
        GroupDataModel *model = new GroupDataModel(QStringList() << "firstName"
                                                   << "lastName");
    
        // Create a JsonDataAccess object and load the .json file. The QDir::currentPath()
        // function returns the current working directory for the app.
        JsonDataAccess jda;
        QVariant list = jda.load(QDir::currentPath() +
                                 "/app/native/assets/employees.json");
    
        // Insert the data into the data model. Because the root of the .json file is an
        // array, a QVariant(QVariantList) is returned from load(). You can provide a
        // QVariantList to a data model directly by using insertList().
        model->insertList(list.value());
    
        qDebug()<<"the size of model is "<size()<<"\n";
    
        // Set the data model for the list view
        listView->setDataModel(model);
    
        // Set the content of the page and display it
        root->setContent(listView);    Application::setScene(root);
    }
    

    with the file employees.json of assets

    [
        {
            "firstName" : "Mike",
            "lastName" : "Chepesky"
            "employeeNumber" : 01840192
        },
        {
            "firstName" : "Westlee",
            "lastName" : "Barichak"
            "employeeNumber" : 47901927
        },
        {
            "firstName" : "Jamie",
            "lastName" : "Lambier"
            "employeeNumber" : 51239657
        },
        {
            "firstName" : "Denise",
            "lastName" : "Marshall"
            "employeeNumber" : 41239520
        },
        {
            "firstName" : "Matthew",
            "lastName" : "Taylor"
            "employeeNumber" : 01963597
        },
        {
            "firstName" : "Mark",
            "lastName" : "Tiegs"
            "employeeNumber" : 65321951
        },
        {
            "firstName" : "Karla",
            "lastName" : "Tetzel"
            "employeeNumber" : 03266987
        },
        {
            "firstName" : "Ian",
            "lastName" : "Dundas"
            "employeeNumber" : 29472012
        },
        {
            "firstName" : "Marco",
            "lastName" : "Cacciacarro"
            "employeeNumber" : 56446691
        }
    ]
    

    On the run, it shows a white screen with no list control.

    Thank you all for your answers, actually problem was not in the code. The problem is in the employees.json file I downloaded from developer site.

     

    [
        {
            "firstName" : "Mike",
            "lastName" : "Chepesky"      // after this ',' is missing
            "employeeNumber" : 01840192
        },
        {
            "firstName" : "Westlee",
            "lastName" : "Barichak"      // after this ',' is missing
            "employeeNumber" : 47901927
        },
        {
            "firstName" : "Jamie",
            "lastName" : "Lambier"    // after this ',' is missing
            "employeeNumber" : 51239657
        },
    
    ....................so on]
    

    means the error occurred when parsing json. Error very stupid . I have checked it sooner.

    So who uses this example json file in their applications. Please correct first, and then use.

     

  • The use of SQLite to store the JSON object

    Hello

    Can someone guide on how to store a JSON object returned after the use of the Adobe provide parser JSON which returns the native object

    as

    resultobject = JSON.decode (data)

    Where the data is a JSON string.

    The 'result' object is a complex subject, but I would like to keep this object because it is in the SQLite database.

    I tried BLOB for the column type but doesn't seem to work to store this object. Ideally, I prefer to use this way to avoid the redesign of the main code as I am currently using the SharedObject method.

    Any ideas?

    Can you just store the data as a BLOB string?

Maybe you are looking for