这是我到目前为止所编写的代码我在XML文件中获取数组中的所有数据,但我只需要打印VehicleId,请告诉我如何做到这一点我是blackberry webservice的新手。
在我的xml文件中我有这个
{"status":1,"message":"Vehicles List","Vehicles":
[{"VehicleId":"47","Fuel":"Petrol","Colour":"Green"},
{"VehicleId":"57","Fuel":"Petrol","Colour":"blue","Used":"True"}]
我在myscreen中的代码是
public final class MyScreen extends MainScreen {
/**
* Creates a new MyScreen object
*/
String inputdata = "";
public MyScreen() {
setTitle("MyTitle");
final VerticalFieldManager vfm = new VerticalFieldManager();
final LabelField lbl[];
lbl = new LabelField[6];
final LabelField jsonresdata = new LabelField();
LabelField jsonResult = new LabelField("Webservice", Field.FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
Getdata();
return true;
}
public void Getdata() {
try{
inputdata = "";
inputdata = inputdata
+ "<?xml version='1.0' encoding='utf-8'?>";
inputdata = inputdata
+ "<soap:Envelope
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
inputdata = inputdata + "<soap:Body>";
inputdata = inputdata
+ "<GetVehicleList xmlns='http://tempuri.org/' />";
inputdata = inputdata + "</soap:Body>";
inputdata = inputdata + "</soap:Envelope>";
final String url =
"http://156.168.2.112:2345/SERVICE.asmx?op=GetVehicleList";
try{
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
ConnectionClass con = new ConnectionClass();
try{
String responsedata = con.CallWebService(url, inputdata,
HttpConnection.POST);
if(responsedata != ""){
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = dbf
.newDocumentBuilder();
ByteArrayInputStream bis = new ByteArrayInputStream(
responsedata.getBytes("UTF-8"));
Document doc = builder.parse(bis);
doc.getDocumentElement().normalize();
final NodeList list;
list = doc
.getElementsByTagName("GetVehicleListResult");
String vehicledata = list.item(0)
.getChildNodes()
.item(0)
.getNodeValue() ;
Dialog.alert(vehicledata);
JSONObject json = new JSONObject(inputdata);
JSONArray a=new JSONArray(json.getString("VehicleId"));
// JSONArray jArray= json.getJSONArray("messages");
for (int i=0; i < a.length(); i++) {
lbl[i]=new LabelField(",");
vfm.add(lbl[i]);
add(vfm);
}
}else{
}
}catch(Exception e){
}}
});
}catch(Exception e){
}}
catch(Exception e){
}
}
};
add(jsonResult);
add(jsonresdata);
}
}