Question

I have the following code...

    // register new user
    ConnectionRequest r = new ConnectionRequest(); 
    r.setUrl(sUrlWebSvc);
    r.setPost(true);

    r.addArgument("Rest", "1");          // 
    r.addArgument("Req", "Register");    // R = register
    r.addArgument("UserName",     findField(f, "txtUserName"));    
    r.addArgument("Password",     findField(f, "txtPassword"));
    r.addArgument("FirstName",    findField(f, "txtFirstName"));
    r.addArgument("LastName",     findField(f, "txtLastName"));
    r.addArgument("Address",      findField(f, "txtAddress"));
    r.addArgument("City",         findField(f, "txtCity"));
    r.addArgument("State",        findField(f, "txtState"));
    r.addArgument("ZipCode",      findField(f, "txtZipCode"));
    r.addArgument("Email",        findField(f, "txtEmail"));
    // show spinning dialog while connecting
    InfiniteProgress prog = new InfiniteProgress();
    Dialog dlg = prog.showInifiniteBlocking();
    r.setDisposeOnCompletion(dlg);
    NetworkManager.getInstance().addToQueueAndWait(r);
    byte[] temp = r.getResponseData();

Could someone please explain how to get the responsed data into a hash table so that I can lookup various items...

Was it helpful?

Solution

Is the response in JSON format or in XML format or CSV?

Assuming JSON format you can use:

JSONParser p = new JSONParser();
Hashtable h = p.parse(new InputStreamReader(new ByteArrayInputStream(temp));

With XML you will get a hierarchy Element object you can traverse from the XMLParser which is pretty similar. Check out the Codename One developer guide for further details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top