我有一个使用json检索值并获取到微调器选择时间的问题
JSON
:
{
"offer_detail":[
{
"movieid":"72",
"date_value":"2014-05-11",
"showtime":[
"10:30 AM",
"2:30 PM",
"6:30 PM",
"9:30 PM"
],
"screen_no":"SCREEN 2",
"id":"186"
}
],
"success":1,
"message":"Successfully found "
}
我试图在各个时间内在微调器内显示showtime 前 - 上午10:30 下午2:30 下午6点30分 9:30 PM
但在我的情况下,它会显示整个showtime
数组,而不是单独显示时间。
这就是我所尝试过的:
c = JSONfunctions
.getJSONfromURL("http://192.168.1.104/OnlineTicketBooking/book_now1.php?movieid='72'");
try {
JSONArray jarray = c.getJSONArray("offer_detail");
ArrayList<String> xyz= new ArrayList<String>();
for(int i = 0; i < jarray.length(); i++){
c = jarray.getJSONObject(i);
xyz.add(c.getString("showtime"));
Log.d("get value",c.getString("showtime"));
}
ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(Booking.this, android.R.layout.simple_spinner_item,xyz);
dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(dataAdapter1);
String cl=spin.getSelectedItem().toString();
String filenameArray[] = cl.split(",");
int size = filenameArray.length;
Log.d("count",""+size);
ArrayList<String> nw = new ArrayList<String>();
for (int j = 0; j < filenameArray.length; j++) {
JSONObject c = jarray.getJSONObject(j);
nw.add(c.getString("showtime"));
Log.d("getvalue",c.getString("showtime"));
}
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(Booking.this, android.R.layout.simple_spinner_item,nw);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(dataAdapter2);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), spin.getSelectedItem().toString(),
Toast.LENGTH_SHORT).show();
String cl=spin.getSelectedItem().toString();
Log.d("classname",cl);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
感谢。
答案 0 :(得分:2)
试试吧......
c = JSONfunctions
.getJSONfromURL("http://192.168.1.104/OnlineTicketBooking/book_now1.php?movieid='72'");
try {
JSONArray jarray = c.getJSONArray("offer_detail");
ArrayList<String> xyz= new ArrayList<String>();
for(int i = 0; i < jarray.length(); i++){
JSONArray timeArray = jarray.getJSONObject(i).getJSONArray("showtime");
for(int j = 0; j < timeArray .length(); j++){
xyz.add(timeArray .getString(j));
Log.d("get value",timeArray .getString(i));
}
}
答案 1 :(得分:0)
c = JSONfunctions
.getJSONfromURL("http://192.168.1.104/OnlineTicketBooking/book_now1.php?movieid='72'");
try {
JSONArray jarray = c.getJSONArray("offer_detail");
ArrayList<String> xyz= new ArrayList<String>();
for(int i = 0; i < jarray.length(); i++){
JSONArray timeArray = jarray.getJSONObject(i).getJSONArray("showtime");
for(int j = 0; j < timeArray .length(); j++){
xyz.add(timeArray .getString(j));
Log.d("get value",timeArray .getString(j));
}
}
试试上面的代码