JSON Help

26 views
Skip to first unread message

Michael Osakede

unread,
Aug 11, 2013, 2:43:18 PM8/11/13
to codenameone...@googlegroups.com
hi,

how do i Parse this URL?"http://208.109.186.98:8080/YellowPage/YellowPage/yelowpage.json"
I have used this code below but i keep getting Null Pointer Exception.:
ConnectionRequest cr = new ConnectionRequest()
        {
            protected void readResponse(InputStream is) throws IOException
            {
                JSONParser p = new JSONParser();
                Hashtable h = p.parse(new InputStreamReader(is));
                Hashtable<Object, Hashtable<String, String>> todoHash = (Hashtable<Object, Hashtable<String, String>>)h.get("");
                Container tasksContainer = findContainer(c.getParent());
               
                for(Hashtable<String, String> values : todoHash.values())
                {
                    //
                    String photoURL = values.get("name");
                    String title = values.get("facebook");
                    System.out.println(photoURL+"::"+title);
                }
          }      
        };
        InfiniteProgress i = new InfiniteProgress();
        Dialog blocking = i.showInifiniteBlocking();
        cr.setDisposeOnCompletion(blocking);
        cr.setPost(false);
        cr.setUrl("http://208.109.186.98:8080/YellowPage/YellowPage/yelowpage.json");
        NetworkManager.getInstance().addToQueue(cr);

how do i make this work?

Michael

Shai Almog

unread,
Aug 12, 2013, 1:44:36 AM8/12/13
to codenameone...@googlegroups.com
Hi Michael,
this should work:

            JSONParser p = new JSONParser();

           
Hashtable h = p.parse(new InputStreamReader(input));
           
Vector<Hashtable<String, Object>> todoHash = (Vector<Hashtable<String, Object>>)h.get("root");
           
           
for(Hashtable<String, Object> entry : todoHash) {
               
String fb = (String)entry.get("facebook");
               
String name = (String)entry.get("name");
               
System.out.println("Fb: " + fb);
               
System.out.println("Name: " + name);
           
}


Reply all
Reply to author
Forward
0 new messages