public void getTicketConsumption(final Handler handler, final String deviceId) {
ShowOnlineConsumeRecordActivity.listData = new ArrayList<HashMap<String, Object>>();
final String url = "http://202.173.255.26:9995/HDServices.asmx/Get_Ticket_Consumption";
httpCilent = new DefaultHttpClient();
new Thread(new Runnable() {
@Override
public void run() {
httpPost = new HttpPost(url);
try {
final List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("deviceid", deviceId));
httpPost.setEntity(new UrlEncodedFormEntity(params));
response = httpCilent.execute(httpPost);
final int statuCode = response.getStatusLine().getStatusCode();
if (statuCode != HttpStatus.SC_OK) {
try {
throw new Exception();
} catch (final Exception e) {
}
} else {
entity = response.getEntity();
final String results = EntityUtils.toString(entity, "GB2312");
final JSONObject obj = new JSONObject(results);
errmsg = obj.getString("Errmsg");
errcode = obj.getString("Errcode");
final JSONArray consumptions = obj.getJSONArray("TicketConsumptions");
final int consumptionsCount = consumptions.length();
if (errmsg.equals("ok") && errcode.equals("0")) {
for (int i = 0; i < consumptionsCount; i++) {
final JSONObject consumption = consumptions.getJSONObject(i);
final String sPrice = consumption.getString("SPrice");
final String spriceTrue = consumption.getString("SpriceTrue");
final String serviceName = consumption.getString("ServiceName");
final String serverContent = consumption.getString("ServerContent");
final String userTime = consumption.getString("userTime");
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("denomination", sPrice);
map.put("amountPayCash", spriceTrue);
map.put("serviceNameRecord", serviceName);
map.put("serviceContentRecord", serverContent);
map.put("validateTime", userTime);
ShowOnlineConsumeRecordActivity.listData.add(map);
}
final Message msg = handler.obtainMessage();
msg.what = MessageContent.MSG_SUCCESS;
handler.sendMessage(msg);
} else if (Integer.parseInt(errcode)<0){
final Message msg = handler.obtainMessage();
msg.what = MessageContent.MSG_ERROR;
handler.sendMessage(msg);
}
}
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final JSONException e) {
e.printStackTrace();
System.out.println("这里有exception" + e.toString());
}
}
}).start();
}
public void ticketValid(final Handler handler, final String deviceId, final String pwd) {
public static HashMap<String, String> ticketValidHashMap;
ticketValidHashMap = new HashMap<String, String>();
final String url = "http://202.173.255.26:9995/HDServices.asmx/TicketValid";
httpCilent = new DefaultHttpClient();
new Thread(new Runnable() {
@Override
public void run() {
httpPost = new HttpPost(url);
try {
final List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("deviceid", deviceId));
params.add(new BasicNameValuePair("cardno", null));
params.add(new BasicNameValuePair("spPasswd", pwd));
httpPost.setEntity(new UrlEncodedFormEntity(params));
response = httpCilent.execute(httpPost);
final int statuCode = response.getStatusLine().getStatusCode();
if (statuCode != HttpStatus.SC_OK) {
try {
throw new Exception();
} catch (final Exception e) {
}
} else {
entity = response.getEntity();
final String results = EntityUtils.toString(entity, "GB2312");
final JSONObject obj = new JSONObject(results);
errmsg = obj.getString("Errmsg");
errcode = obj.getString("Errcode");
if (errmsg.equals("ok") && errcode.equals("0")) {
final String spCode = obj.getJSONObject("Ticket").getString("SPcode");
final String sPrice = obj.getJSONObject("Ticket").getString("SPrice");
final String cNameShort = obj.getJSONObject("Ticket").getString("Cnameshort");
final String serviceName = obj.getJSONObject("Ticket").getString("ServiceName");
final String serverContent = obj.getJSONObject("Ticket").getString("ServerContent");
ticketValidHashMap.put("spCode", spCode);
ticketValidHashMap.put("sPrice", sPrice);
ticketValidHashMap.put("cNameShort", cNameShort);
ticketValidHashMap.put("serviceName", serviceName);
ticketValidHashMap.put("serverContent", serverContent);
final Message msg = handler.obtainMessage();
msg.what = MessageContent.MSG_SUCCESS;
handler.sendMessage(msg);
} else if (Integer.parseInt(errcode)<0){
final Message msg = handler.obtainMessage();
msg.what = MessageContent.MSG_ERROR;
handler.sendMessage(msg);
}
}
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final JSONException e) {
e.printStackTrace();
System.out.println("这里有exception" + e.toString());
}
}
}).start();
}
var employees = [
{ "firstName":"Bill" , "lastName":"Gates" },
{ "firstName":"George" , "lastName":"Bush" },
{ "firstName":"Thomas" , "lastName": "Carter" }
]
可以像这样访问 JavaScript 对象数组中的第一项:employees[0].lastName
可以直接修改数据:employees[0].lastName = "Jobs"