我是黑莓新手我不知道如何在黑莓使用矢量存储数据。 我需要存储这些数据,所以请帮助我。
{
"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
}
我想将所有数据存储在一个向量中。 提前谢谢。
答案 0 :(得分:1)
试试这个 -
Vector vector = new Vector();
在for循环中,将项添加到向量中。
vector.addElement(new your_object(value_1,value_2......));