Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
dcharya
Posts: 74
Registered: ‎03-04-2012
My Device: developer
Accepted Solution

JSONData Handling and storing for further use in application.

[ Edited ]

Hi All,

 

I am facing a problem here. Actually I am bit confused.. I am not getting a way to Handel JSON Response that I am getting from web service. By handling response here I mean like in java we have collections (Vectors and arraylist) to store and use data in other classes by making them static or something like that. The approach that I have been following with blackberry java development for processing and handling data was I use to make bean classes and according to response I use to create data handler but here I am confused how do I do this. As far as parsing Soon response is concern thanks to contributors of this forum I achieved it successfully.

 

I am attaching files to show the approach that I have following till now for data handling.

 

 

Json Format :: 


{

  "postfeed": {

    "blocksize": 12,

    "offset": "1",

    "postcount": 699,

    "sticky": "1"

  },

  "hoteldetails": {

    "hotel_id": "109",

    "title": "MTL Hotel 1",

    "desc": null,

    "hotel_imageURL": "sites\/default\/files\/hotelimages\/Koala.jpg",

    "location": {

      "city": "Montreal",

      "country_name": "Canada",

      "latitude": "0.000000",

      "longitude": "0.000000",

      "name": null,

      "phone": null,

      "postal_code": "E4W3W9",

      "street": "3344 de la Montagne"

    },

    "currency": "$",

    "general_hotel": null,

    "title1": null,

    "title2": null,

    "title3": null,

    "url1": null,

    "url2": null,

    "url3": null,

    "contact": {

      "email": "abc@efc.com",

      "facebook": "url",

      "twitter": "url"

    },

    "cityid": "108"

  },

  "posts": {

    "sticky": {

      "title": "double stick again",

      "description": "ok",

      "id": "8244",

      "comments": "1",

      "type": "Event",

      "optype": true,

      "joined": "0",

      "guests": "1",

      "optext": "Join",

      "created_time": "1359554162",

      "cost": "5",

      "from": "01\/30\/2013 08:55",

      "to": "",

      "where": "some place",

      "img": "sites\/default\/files\/imagecache\/service_cache\/posttypes\/1113-Event_Icon3.png",

      "post_picture": null,

      "posterdetails": {

        "name": "John Smith",

        "id": "1863",

        "occupation": "Product Development Manager today",

        "employer": "",

        "roles": {

          "2": "authenticated user",

          "3": "xyz"

        },

        "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg"

      },

      "flags": {

        "1": {

          "flaginfo": {

            "flag_name": "like",

            "flag_conf": {

              "flag_text": "Like This",

              "flag_description": "",

              "unflag_text": "Liked!",

              "unflag_description": "",

              "can_unflag": 0,

              "flag_item": {

                "hotelpost": "hotelpost",

                "hotelcomment": 0,

                "user": 0

              },

              "flag_class": "likepost",

              "flag_type": "1",

              "show_flag": {

                "full": "full",

                "teaser": "teaser"

              }

            },

            "flagid": 1

          },

          "currentuser": false

        },

        "2": {

          "flaginfo": {

            "flag_name": "reportpost",

            "flag_conf": {

              "flag_text": "bad post?",

              "flag_description": "",

              "unflag_text": "flagged",

              "unflag_description": "",

              "can_unflag": 0,

              "flag_item": {

                "hotelpost": "hotelpost",

                "hotelcomment": 0,

                "user": 0

              },

              "flag_class": "",

              "flag_type": "0",

              "show_flag": {

                "full": "full",

                "teaser": "teaser"

              }

            },

            "flagid": 2

          },

          "currentuser": false

        }

      },

      "likecount": "1",

      "timeago": "16 hours ago"

    },

    "nonsticky": [

      {

        "title": "-",

        "description": null,

        "id": "8260",

        "comments": "0",

        "type": "Status",

        "optype": false,

        "optext": "",

        "created_time": "1359583784",

        "cost": null,

        "from": null,

        "to": null,

        "where": null,

        "img": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1864-1d5d622cc4b5904845c786d9156073b5.jpg",

        "post_picture": "sites\/default\/files\/hotelpostshare\/2531-mypicture.png",

        "posterdetails": {

          "name": "Ben Stob",

          "id": "1864",

          "occupation": "Front Desk",

          "employer": "Novotel",

          "roles": {

            "2": "authenticated user",

            "4": "xyzf"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1864-1d5d622cc4b5904845c786d9156073b5.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "0",

        "timeago": "8 hours ago"

      },

      {

        "title": "posting regular",

        "description": "yup",

        "id": "8259",

        "comments": "0",

        "type": "Event",

        "optype": true,

        "joined": "0",

        "guests": "0",

        "optext": "Join",

        "created_time": "1359579332",

        "cost": "45",

        "from": "01\/30\/2013 17:00",

        "to": "01\/30\/2013 20:00",

        "where": "no",

        "img": "sites\/default\/files\/imagecache\/service_cache\/posttypes\/1113-Event_Icon3.png",

        "post_picture": null,

        "posterdetails": {

          "name": "John Smith",

          "id": "1863",

          "occupation": "Product Development Manager today",

          "employer": "",

          "roles": {

            "2": "authenticated user",

            "3": "ssssl"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "0",

        "timeago": "9 hours ago"

      },

      {

        "title": "Test",

        "description": "Kook",

        "id": "8258",

        "comments": "0",

        "type": "Event",

        "optype": true,

        "joined": "0",

        "guests": "0",

        "optext": "Join",

        "created_time": "1359579276",

        "cost": "10",

        "from": "01\/30\/2013 15:54",

        "to": "01\/30\/2013 20:54",

        "where": "Some place",

        "img": "sites\/default\/files\/imagecache\/service_cache\/posttypes\/1113-Event_Icon3.png",

        "post_picture": null,

        "posterdetails": {

          "name": "John Smith",

          "id": "1863",

          "occupation": "Product Development Manager today",

          "employer": "",

          "roles": {

            "2": "authenticated user",

            "3": "efasdf"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "0",

        "timeago": "9 hours ago"

      },

      {

        "title": "This is what happens when someone posts a really long post on the iphone does it have any limist or does it just stop in terms of a cutoff or does it keep going because sometimes life is just great an",

        "description": null,

        "id": "8257",

        "comments": "0",

        "type": "Status",

        "optype": false,

        "optext": "",

        "created_time": "1359578883",

        "cost": null,

        "from": null,

        "to": null,

        "where": null,

        "img": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg",

        "post_picture": null,

        "posterdetails": {

         "name": "John Smith",

          "id": "1863",

          "occupation": "Product Development Manager today",

          "employer": "",

          "roles": {

            "2": "authenticated user",

            "3": "rtgfvasfd"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "1",

        "timeago": "9 hours ago"

      },

      {

        "title": "Daily Event post testing",

        "description": "I am posting a daily today sunday at 10am , to start at 3pm today...everyday, event starts at 10pm everyday , starting on the 20th and ending on 31...everyday this post will appear. ",

        "id": "8256",

        "comments": "0",

        "type": "Event",

        "optype": true,

        "joined": "0",

        "guests": "0",

        "optext": "Join",

        "created_time": "1359576486",

        "cost": "0",

        "from": "01\/30\/2013 22:00",

        "to": "",

        "where": "lounge",

        "img": "sites\/default\/files\/imagecache\/service_cache\/posttypes\/1113-Event_Icon3.png",

        "post_picture": null,

        "posterdetails": {

          "name": "Ben Stob",

          "id": "1864",

          "occupation": "Front Desk",

          "employer": "Novotel",

          "roles": {

            "2": "authenticated user",

            "4": "dfgagvc"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1864-1d5d622cc4b5904845c786d9156073b5.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

             },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "0",

        "timeago": "10 hours ago"

      },

      {

        "title": "an event for push",

        "description": "testing",

        "id": "8255",

        "comments": "0",

        "type": "Event",

        "optype": true,

        "joined": "0",

        "guests": "0",

        "optext": "Join",

        "created_time": "1359575590",

        "cost": "10",

        "from": "01\/30\/2013 14:53",

        "to": "01\/30\/2013 20:00",

        "where": "some place",

        "img": "sites\/default\/files\/imagecache\/service_cache\/posttypes\/1113-Event_Icon3.png",

        "post_picture": null,

        "posterdetails": {

          "name": "John Smith",

          "id": "1863",

          "occupation": "Product Development Manager today",

          "employer": "",

          "roles": {

            "2": "authenticated user",

            "3": "sdfdsafa"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "0",

        "timeago": "10 hours ago"

      },

      {

        "title": "testing to see if u get a push!",

        "description": null,

        "id": "8254",

        "comments": "0",

        "type": "Status",

        "optype": false,

        "optext": "",

        "created_time": "1359575519",

        "cost": null,

        "from": null,

        "to": null,

        "where": null,

        "img": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg",

        "post_picture": null,

        "posterdetails": {

          "name": "John Smith",

          "id": "1863",

          "occupation": "Product Development Manager today",

          "employer": "",

          "roles": {

            "2": "authenticated user",

            "3": "werew"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-1863-30f1fa55def8214a5b654bdfb0827275.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "0",

        "timeago": "10 hours ago"

      },

      {

        "title": "This is the best pose",

        "description": null,

        "id": "8253",

        "comments": "0",

        "type": "Status",

        "optype": false,

        "optext": "",

        "created_time": "1359575013",

        "cost": null,

        "from": null,

        "to": null,

        "where": null,

        "img": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-2138-4bab84bb9dae51eacad7af5c0334a8a8.jpg",

        "post_picture": "sites\/default\/files\/hotelpostshare\/2528-mypicture.png",

        "posterdetails": {

          "name": "Shakira Ayoub",

          "id": "2138",

          "occupation": "Nurse",

          "employer": "St Mary",

          "roles": {

            "2": "authenticated user"

          },

          "picture": "sites\/default\/files\/imagecache\/service_cache\/pictures\/picture-2138-4bab84bb9dae51eacad7af5c0334a8a8.jpg"

        },

        "flags": {

          "1": {

            "flaginfo": {

              "flag_name": "like",

              "flag_conf": {

                "flag_text": "Like This",

                "flag_description": "",

                "unflag_text": "Liked!",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "likepost",

                "flag_type": "1",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 1

            },

            "currentuser": false

          },

          "2": {

            "flaginfo": {

              "flag_name": "reportpost",

              "flag_conf": {

                "flag_text": "bad post?",

                "flag_description": "",

                "unflag_text": "flagged",

                "unflag_description": "",

                "can_unflag": 0,

                "flag_item": {

                  "hotelpost": "hotelpost",

                  "hotelcomment": 0,

                  "user": 0

                },

                "flag_class": "",

                "flag_type": "0",

                "show_flag": {

                  "full": "full",

                  "teaser": "teaser"

                }

              },

              "flagid": 2

            },

            "currentuser": false

          }

        },

        "likecount": "1",

        "timeago": "10 hours ago"

      }

    ]

  },

  "custom_app": {

    "hotel_name": "mtl hotel--1--",

    "primary_color": "#1f74be",

    "secondary_color": "#90958c",

    "icon_color": "#fc69fc",

    "logo": "sites\/default\/files\/custom_app\/logo\/logo-1357129245.jpg",

    "primary_color_dark": "#3388d2",

    "icon_color_name": "PINK"

  },

  "rssposts": [

    {

      "title": "BlackBerry review: The good and bad of the new Z10",

      "desc": "<img width=\"460\" height=\"259\" src=\"http:\/\/www.cbc.ca\/gfx\/images\/news\/topstories\/2013\/01\/30\/hi-blackberry-z10-stock-852-6col.jpg\"><br\/><p>Peter Nowak reviews the new Z10 smartphone from BlackBerry. Bottom line: pretty cool, great speed, but needs more apps and a better map program.<\/p>",

      "link": "http:\/\/www.cbc.ca\/news\/technology\/story\/2013\/01\/30\/f-blackberry-10-review.html?cmp=rss",

      "date": "Wed, 30 Jan 2013 19:49:47 EST",

      "feedid": "18",

      "record": {

        "feedid": "18",

        "link": "http:\/\/rss.cbc.ca\/lineup\/topstories.xml",

        "title": "CBC Top Stories",

        "description": "This is the best source out there!",

        "icon_path": "",

        "block": "9",

        "timestamp": "1359140650",

        "feedtypeid": "0"

      },

      "ts": 1359593387,

      "type": "rss"

    },

    {

      "title": "RIM changes name to BlackBerry as BB10 launches",

      "desc": "<img width=\"460\" height=\"259\" src=\"http:\/\/www.cbc.ca\/gfx\/images\/news\/topstories\/2013\/01\/30\/hi-heins-blackberry10-6col.jpg\"><br\/><p>Research In Motion launches two BlackBerry 10 smartphones, banking on the hotly anticipated line of devices to save the company.<\/p>",

      "link": "http:\/\/www.cbc.ca\/news\/business\/story\/2013\/01\/29\/business-rim-blackberry.html?cmp=rss",

      "date": "Wed, 30 Jan 2013 19:25:54 EST",

      "feedid": "18",

      "record": {

        "feedid": "18",

        "link": "http:\/\/rss.cbc.ca\/lineup\/topstories.xml",

        "title": "CBC Top Stories",

        "description": "This is the best source out there!",

        "icon_path": "",

        "block": "9",

        "timestamp": "1359140650",

        "feedtypeid": "0"

      },

      "ts": 1359591954,

      "type": "rss"

    },

    {

      "title": "Deadly storms, tornadoes hammer southeast U.S.",

      "desc": "<img width=\"460\" height=\"259\" src=\"http:\/\/www.cbc.ca\/gfx\/images\/news\/topstories\/2013\/01\/30\/hi-georgia-tornado-852-0391-6col.jpg\"><br\/><p>A massive storm system raked the southeast U.S. on Wednesday, spawning tornadoes and dangerous winds that overturned cars on a Georgia interstate and demolished homes and businesses, killing at least two people.<\/p>",

      "link": "http:\/\/www.cbc.ca\/news\/world\/story\/2013\/01\/30\/tornado-georgia-us-storms-southeast.html?cmp=rss",

      "date": "Wed, 30 Jan 2013 19:20:25 EST",

      "feedid": "18",

      "record": {

        "feedid": "18",

        "link": "http:\/\/rss.cbc.ca\/lineup\/topstories.xml",

        "title": "CBC Top Stories",

        "description": "This is the best source out there!",

        "icon_path": "",

        "block": "9",

        "timestamp": "1359140650",

        "feedtypeid": "0"

      },

      "ts": 1359591625,

      "type": "rss"

    },

    {

      "title": "Syria says Israeli warplanes hit military site",

      "desc": "<img width=\"460\" height=\"259\" src=\"http:\/\/www.cbc.ca\/gfx\/images\/news\/topstories\/2013\/01\/30\/hi-world-israel-jet-lebanon-6col.jpg\"><br\/><p>Israel conducted a rare airstrike on a military target inside Syria, foreign officials and Syrian state TV say, amid fears President Bashar al-Assad's regime is providing weapons to the Islamic militant group Hezbollah.<\/p>",

      "link": "http:\/\/www.cbc.ca\/news\/world\/story\/2013\/01\/30\/israel-lebanon-syria-jets.html?cmp=rss",

      "date": "Wed, 30 Jan 2013 18:38:05 EST",

      "feedid": "18",

      "record": {

        "feedid": "18",

        "link": "http:\/\/rss.cbc.ca\/lineup\/topstories.xml",

        "title": "CBC Top Stories",

        "description": "This is the best source out there!",

        "icon_path": "",

        "block": "9",

        "timestamp": "1359140650",

        "feedtypeid": "0"

      },

      "ts": 1359589085,

      "type": "rss"

    }

  ],

  "facebookposts": [

   

  ],

  "twitterposts": [

   

  ]

}

Deepak Charya
Please use plain text.
Developer
dcharya
Posts: 74
Registered: ‎03-04-2012
My Device: developer

Re: JSONData Handling and storing for further use in application.

No hints for this problem ???
Deepak Charya
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: JSONData Handling and storing for further use in application.

Hi! There are classes in Qt which are similar to Java classes. For example ArrayList is equivalent to QList.

For presenting the data there are many options:

1) parse JSON, put every item into QVariantMap and insert these maps into GroupDataModel. Assign this model to ListView to display the data.

2) If you don't need sorting functionality, use ArrayDataModel.

3) If you prefer to keep data strictly-typed you can use any container (for example QList) and just wrap the data into your own DataModel subclass.

Reading docs on ListView and different DataModel types should give a start.

Hope this helps.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
dcharya
Posts: 74
Registered: ‎03-04-2012
My Device: developer

Re: JSONData Handling and storing for further use in application.

Hi Zmey,

 

Thanks for reply :smileyhappy:, I followed what u suggested in your post. I got success in parsing JSON data and stored it in QVariantList and QVariantMap as per requirement I don't know what I am missing here and facing a problem :Sweatdrop:.

 

The problem is on binding data model with listview created in QML in output I am getting rows in listview equivalent to the size of datamodel but when I try to bind particular tag value with label using ListItemData.id for example say, it does not show anything

 

Here is my code snippet 

QVariantMap lobbyJson = ja.loadFromBuffer(response).value<
				QVariantMap>();
		QVariantMap qPostMap = lobbyJson.value("posts").value<QVariantMap>();

		QVariantList qPostList_NonSticky = lobbyJson.value("rssposts").value<QVariantList>();
//		QVariantList list = lobbyJson.value("twitterposts").toList();
		GroupDataModel *dataModel = new GroupDataModel();
		ArrayDataModel *arrModel = new ArrayDataModel;
		lobbyList =  bb::cascades::Application::instance()->findChild<
							ListView*>("listView");

				lobbyList->setDataModel(arrModel);
		for(int i =0 ; i<qPostList_NonSticky.size();i++){
					QVariantMap postFeed = qPostList_NonSticky.at(i).toMap();
					QString id = postFeed.value("title").toString();
					qDebug()<<"POST TITLE IS --- " << id;
					arrModel->append(postFeed);
				}
//		arrModel->append(list);
//		dataModel->insertList(list);
//		dataModel->setGrouping(ItemGrouping::None);

		/*for(int i =0 ; i<qPostList_NonSticky.size();i++){
			QVariantMap postFeed = qPostList_NonSticky.at(i).value<QVariantMap>();
//			QString id = postFeed.value("title").toString();
//			qDebug()<<"POST TITLE IS --- " << id;
			dataModel->insert(i,postFeed);
		}*/


		qDebug() << "Lobby Data Handling -- " << lobbyJson;
		mActivityIndicator = bb::cascades::Application::instance()->findChild<ActivityIndicator*>("LobbyIndicator");
		mActivityIndicator->stop();

 

 

Can you please suggest me on looking at my json response that i posted earlier which data model wud be suitable for me that would be a great help. I am sharing QML as well 

 

 

import bb.cascades 1.0
import bb.system 1.0

Page {
    id: hotelLobby
    objectName: "HotelLobby"
    actionBarVisibility: ChromeVisibility.Hidden
    paneProperties: NavigationPaneProperties {
    }
    Container {
        layout: DockLayout {
        }
        ActivityIndicator {
            id: loginIndicator
            objectName: "LobbyIndicator"
            preferredWidth: 400
            preferredHeight: 400
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            onStopped: {
                filePathFailedToast.show();
            }
        }
        /*ListView {
         * id: lobbyList
         * objectName: "listHotelLobby"
         * listItemComponents: [
         * ListItemComponent {
         * }
         * ]
         * }*/
        ListView {
            id: list
            objectName: "listView"
            preferredHeight: maxHeight
            listItemComponents: [
                ListItemComponent {
                    type: "item"
                    PhotoListItem {
                    }
                }
            ]
            /*onTriggered: {
             * filePathFailedToast.show();
             * }*/
        }
        /*ListView {
            id: listView
            preferredHeight: maxHeight
            objectName: "listView"
            listItemComponents: [
                ListItemComponent {
                    type: "List"
                    PhotoListItem {
                    }
                }
            ]
            onTriggered: {
                console.log("selected_index: " + indexPath)
            }
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
        }*/
    }
    /*attachedObjects: [
     * GroupDataModel {
     * id: dataModel
     * }
     * ]*/
    onCreationCompleted: {
        loginIndicator.start();
        console.log("Getting Hotel ID");
        app.btnAcceptTermsClick();
        console.log("Loading Hotel Lobby Start Here" + app.iCase);
    }
}

 

Regards

Deepak Charya
Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha

Re: JSONData Handling and storing for further use in application.

Let me show you my architecture to works with JSON API witch contains resources and collection. 

 

What I did , is to create one Object for each Resource . For exemple : Person, Book, Groups.

Person : public QObject 

{

Q_PROPERTY (QString username READ usernameWRITE setUserName NOTIFY usernameChanged)

...

}

 

And for each object, I create a parser : PersonParser, BookParser, groupsParser. 

PersonParser {

static Person * parse(const QString& json);

}

 

To get parse a Person, I just have to wite : 

Person * person  = PersonParser::smileytongue:arse(json);

 

Then, you can use a GroupDataModel , or ArrayDataModel ( convert QObject to QVariant) and insert each person : 

dataModel->insert(person);

 

And from the qml ListView : 

ListItemComponent {

Label {

ListItemData.username

}

}

 

 

For Collection, it's pretty easy. Use QList<Person*> to describe a collection of Person. You can set a specific method in your parser like : 

list = PersonParser::smileytongue:arseCollection(const QString& json);

 

Tips : A good idea, is to create a Resource and Collection class, which are the common ancestor class of each Resource : 

class Person : public Resource 

 

 

 

 

 

 

a lover of Qt
Please use plain text.
Developer
dcharya
Posts: 74
Registered: ‎03-04-2012
My Device: developer

Re: JSONData Handling and storing for further use in application.

Thanks dridk for sharing the architecture that u follow with us but being a beginner I am quite confused and not getting right direction where should do I go. I came all this long with the help of contributors and developers here who are posting there code and suggestion over here thanks to all of them, but I am looking for a perfect solution I am getting confused by reading too much and try different ways for achieving my goal. Please share or suggest something that help me to learn this and will help others who are facing similar problem.

 

:Helpsmilie:

Deepak Charya
Please use plain text.
Developer
dcharya
Posts: 74
Registered: ‎03-04-2012
My Device: developer

Re: JSONData Handling and storing for further use in application.

No suggestion for this problem.................???? 

 

:smileysad::smileysad::smileysad::smileysad::smileysad:

Deepak Charya
Please use plain text.
Developer
dcharya
Posts: 74
Registered: ‎03-04-2012
My Device: developer

Re: JSONData Handling and storing for further use in application.

Greetings All,

 

Thanks for support and suggestions. Problem is solved.

 

Regards

Deepak Charya
Please use plain text.