How to pass array of json result into another form

42 views
Skip to first unread message

ein...@gmail.com

unread,
Sep 23, 2016, 7:04:49 AM9/23/16
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device

I am using NetBean tool. 
This is my json result:
{status=1.0, info=[{tranSource=LAGOS, tranDest=UK, tranStation=AGO, tranDate=2016-09-28, tranTime=6:30PM}, {tranSource=LAGOS, tranDest=USA, tranStation=OJOTA, tranDate=2016-09-21, tranTime=6:30PM}]}
LAGOS
UK
AGO
2016-09-28
6:30PM
LAGOS
USA
OJOTA
2016-09-21
6:30PM
I am having challenge on how to pass this result into another form in table format:(Source,Destination,Station,Date,Time,LINK).
i have implemented getters and setter for the result.
public void findTran(String Name,String Port,String Source,String Dest,String Stat,String Date,String Check){
        ConnectionRequest req;
        req = new ConnectionRequest(){
           Map<String, Object> h;
            
            @Override
             protected void postResponse(){
                 Display.getInstance().callSerially(() -> {
                     Double status = (Double) h.get("status");
                     System.out.println(status);                     
                     //String tranName = appUser.getTransource();
                     if (!"".equals(status) && status == 1.0)  {
                         showForm("FindResult", null);
                     }else{
                         //((Dialog) Display.getInstance().getCurrent()).dispose();
                         Dialog.show("Error", "There is no match", "OK", null);
                     }
                 });
            }
            @Override
            protected void readResponse(InputStream input) throws IOException{
                JSONParser p = new JSONParser();
                //InputStreamReader inp = new InputStreamReader(input);
                InputStreamReader inp = new InputStreamReader(input, "UTF-8");
                h = p.parseJSON(inp);
                Double status = (Double) h.get("status");
                System.out.println(status);
                System.out.println("" + h);
                if(status == 1.0){
                ArrayList<HashMap<String, String>> info = (ArrayList<HashMap<String, String>>) h.get("info");
                     for (int i = 0; i < info.size(); i++) {
                         HashMap<String, String> object = (HashMap<String, String>) info.get(i);
                         String transource = (String) object.get("tranSource");
                         System.out.println(transource);
                         String trandest = (String) object.get("tranDest");
                         System.out.println(trandest);
                         String transtation = (String) object.get("tranStation");
                         System.out.println(transtation);
                         String trandate = (String) object.get("tranDate");
                         System.out.println(trandate);
                         String trantime = (String) object.get("tranTime");
                         System.out.println(trantime);
                         if (!"".equals(transource))  {
                             appUser = new AppUsers(transource,trandest,transtation,trandate,trantime);
                         } else {
                         }
                     }
                }       
            }
        };
    
    req.setUrl("/info.php");
    req.setPost(false); 
    req.setContentType("application/json");
    req.setHttpMethod("GET");
    req.addArgument("tranName", Name);
    req.addArgument("tranPort", Port); 
    req.addArgument("tranSource", Source);
    req.addArgument("tranDest", Dest);
    req.addArgument("tranStation", Stat); 
    req.addArgument("tranDate", Date); 
    req.addArgument("tranCheck", Check);
        
    
    InfiniteProgress prog = new InfiniteProgress();
    Dialog dlg = prog.showInifiniteBlocking();
    req.setDisposeOnCompletion(dlg);
    //NetworkManager.getInstance().addToQueue(req);
    NetworkManager.getInstance().addToQueueAndWait(req);
    }
public class AppUsers {
    private String transource;
    private String trandest;
    private String transtation;
    private String trandate;
    private String trantime;
    

   
    public String getTransource() {
        return transource;
    }
    public void setTransource(String transource) {
        this.transource = transource;
    }

   
    public String getTrandest() {
        return trandest;
    }
    public void setTrandest(String trandest) {
        this.trandest = trandest;
    }

    
    public String getTranstation() {
        return transtation;
    }
    public void setTranstation(String transtation) {
        this.transtation = transtation;
    }

    
    public String getTrandate() {
        return trandate;
    }
    public void setTrandate(String trandate) {
        this.trandate = trandate;
    }

    
    public String getTrantime() {
        return trantime;
    }
    public void setTrantime(String trantime) {
        this.trantime = trantime;
    }

    
    public AppUsers(String transource, String trandest, String transtation, String trandate,String trantime){
        this.transource = transource;
        this.trandest = trandest;
        this.transtation = transtation;
        this.trandate = trandate;
        this.trantime = trantime;
        
    }
    
}
How can i display the result on the FindResult form i created using designer.

ein...@gmail.com

unread,
Sep 23, 2016, 7:26:06 AM9/23/16
to CodenameOne Discussions, ein...@gmail.com
This is an additional information:
To create another form in table format:(Source,Destination,Station,Date,Time,LINK).
Source |Destination|Station|Date             |Time     |LINK
LAGOS|UK           |AGO   |2016-09-28 |6:30PM |now
LAGOS|USA         |OJOTA|2016-09-21 |6:30PM |now

How can i display the result on the FindResult form i created using designer and on click now
link it populate it into another form.

Shai Almog

unread,
Sep 24, 2016, 1:55:27 AM9/24/16
to CodenameOne Discussions, ein...@gmail.com
Just store the data in a variable within the state machine or other class.

ein...@gmail.com

unread,
Sep 25, 2016, 9:32:27 AM9/25/16
to CodenameOne Discussions, ein...@gmail.com
I have store the data into another class. Please give me sample on how to display it into another form. Remember that json can return more values depend on the record store in source database.

Shai Almog

unread,
Sep 26, 2016, 12:06:40 AM9/26/16
to CodenameOne Discussions, ein...@gmail.com
You need a reference to the instance of this class. Just create a member variable of that class in your state machine and store the data there.
Reply all
Reply to author
Forward
0 new messages