-1

我是新的黑莓,我不知道如何存儲數據在黑莓使用矢量。 我需要存儲這些數據,所以請幫助我。如何在向量中存儲數據?

{ 
    "menu": { 
     "id": "Home", 
     "menuitem": [ 
      { 
       "type": "form", 
       "name": "Order", 
       "url": "http://domain/oredr.aspx", 
       "Row": [ 
        { 
         "Index": "1", 
         "Control": [ 
          { 
           "type": "LB", 
           "align": "Left", 
           "send": "No", 
           "value": "User Name", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "TB", 
           "align": "Right", 
           "send": "Yes", 
           "value": "", 
           "param": "username", 
           "maxlength": "25", 
           "ctype": "Alpha" 
          } 
         ] 
        }, { 
         "Index": "2", 
         "Control": [ 
          { 
           "type": "LB", 
           "align": "Left", 
           "send": "No", 
           "value": "Mobile No", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "TB", 
           "align": "Right", 
           "send": "Yes", 
           "value": "", 
           "param": "MobileNo", 
           "maxlength": "10", 
           "ctype": "Numeric" 
          } 
         ] 
        }, { 
         "Index": "3", 
         "Control": [ 
          { 
           "type": "LB", 
           "align": "Left", 
           "send": "No", 
           "value": "Email ID", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "TB", 
           "align": "Right", 
           "send": "Yes", 
           "value": "", 
           "param": "email", 
           "maxlength": "50", 
           "ctype": "Email" 
          } 
         ] 
        }, { 
         "Index": "4", 
         "Control": [ 
          { 
           "type": "None", 
           "align": "Left", 
           "send": "No", 
           "value": "", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "BT", 
           "align": "Center", 
           "send": "No", 
           "value": "Submit", 
           "param": "", 
           "maxlength": "", 
           "ctype": "Submit" 
          } 
         ] 
        } 
       ] 
      }, { 
       "type": "form", 
       "name": "Stock", 
       "url": "http://domain/stock.aspx", 
       "Row": [ 
        { 
         "Index": "1", 
         "Control": [ 
          { 
           "type": "LB", 
           "align": "Left", 
           "send": "No", 
           "value": "Select Medium", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "CB", 
           "align": "Right", 
           "send": "Yes", 
           "value": "Select Medium", 
           "param": "medium", 
           "maxlength": "", 
           "ctype": "", 
           "Item": [ 
            { 
             "name": "Yes" 
            }, { 
             "name": "No" 
            } 
           ] 
          } 
         ] 
        }, { 
         "Index": "2", 
         "Control": [ 
          { 
           "type": "None", 
           "align": "Left", 
           "send": "No", 
           "value": "", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "BT", 
           "align": "Center", 
           "send": "No", 
           "value": "Submit", 
           "param": "", 
           "maxlength": "", 
           "ctype": "Submit" 
          } 
         ] 
        } 
       ] 
      }, { 
       "type": "form", 
       "name": "Custom", 
       "url": "http://domain/custom.aspx", 
       "Row": [ 
        { 
         "Index": "1", 
         "Control": [ 
          { 
           "type": "LB", 
           "align": "Left", 
           "send": "No", 
           "value": "Offer Type", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "DD", 
           "align": "Right", 
           "send": "Yes", 
           "value": "", 
           "param": "offertype", 
           "maxlength": "", 
           "ctype": "", 
           "Item": [ 
            { 
             "name": "Marketing" 
            }, { 
             "name": "Promotional" 
            } 
           ] 
          } 
         ] 
        }, { 
         "Index": "2", 
         "Control": [ 
          { 
           "type": "None", 
           "align": "Left", 
           "send": "No", 
           "value": "", 
           "param": "", 
           "maxlength": "", 
           "ctype": "" 
          }, { 
           "type": "BT", 
           "align": "Center", 
           "send": "No", 
           "value": "Submit", 
           "param": "", 
           "maxlength": "", 
           "ctype": "Submit" 
          } 
         ] 
        } 
       ] 
      } 
     ] 
    } 
} 

我解析成功使用json解析器。

try { 
     JSONObject root = new JSONObject(Data.data).getJSONObject("menu"); 
     JSONArray array = root.getJSONArray("menuitem"); 

    System.out.println("strMenu=="+strMenu); 
    for(int loop=0; loop<array.length(); loop++){ 
     System.out.println(array.getJSONObject(loop).get("type")); 
     System.out.println(array.getJSONObject(loop).get("name")); 
     System.out.println(array.getJSONObject(loop).get("url")); 
     JSONArray rows = array.getJSONObject(loop).getJSONArray("Row"); 
     for(int innerLoop=0; innerLoop<rows.length();innerLoop++){ 
      System.out.println(rows.getJSONObject(innerLoop).get("Index")); 
      JSONArray controll = rows.getJSONObject(innerLoop).getJSONArray("Control"); 
      for(int innermostLoop =0; innermostLoop<controll.length(); innermostLoop++){ 
       System.out.println(controll.getJSONObject(innermostLoop).get("type")); 
       System.out.println(controll.getJSONObject(innermostLoop).get("align")); 
       System.out.println(controll.getJSONObject(innermostLoop).get("send")); 
       System.out.println(controll.getJSONObject(innermostLoop).get("value")); 
       System.out.println(controll.getJSONObject(innermostLoop).get("param")); 
       System.out.println(controll.getJSONObject(innermostLoop).get("maxlength")); 
       System.out.println(controll.getJSONObject(innermostLoop).get("ctype")); 


       if(controll.getJSONObject(innermostLoop).get("type").equals("DD")) 
       { 
        JSONArray item=controll.getJSONObject(innermostLoop).getJSONArray("Item"); 
        for(int i=0;i<item.length();i++) 
        { 
         System.out.println(item.getJSONObject(i).get("name")); 
        } 

       } 

      } 
     } 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
    System.out.println("ZZZZZZZZ error ZZZZZZZ"); 
    // TODO: handle exception 
} 

我想將所有數據存儲在一個向量中。 在此先感謝。

回答

1

試試這個 -

Vector vector = new Vector(); 

你的for循環中,將項目添加到載體。

vector.addElement(new your_object(value_1,value_2......)); 
+0

新your_object(值1,值......)表示,請給我解釋一下更哥們Signare – user1443941

+0

我想根據我的JSON數據存儲。 – user1443941

+0

你想存儲什麼值。 String type = array.getJSONObject(loop).get(「type」);然後將該String類型添加到您的矢量以代替value_1。像那樣。 – Signare

相關問題