在java.lang.String类型的300上的值5am无法转换为JSONObject

时间:2014-05-02 05:53:19

标签: android json

{
    "message":"Task Title field is required.\nTask Description field is required.\nFrom Amount field is required.\nTo Amount field is required.\naddress field is required.\nzipcode field is required.\nlocationname field is required.\n",
    "task_location":0,

    "taskers":[{
    "worker_state":null,
    "worker_app_approved":"1",
    "password":"25d55ad283aa400af464c76d713c07ad",
    "paypal_verified":"1",
    "first_name":"Khushi",
    "phone_no":null,
    "is_pro_approve":"0",
    "email_verification_code":"jyQlGbryzJae",
    "worker_home_neighborhood":null,
    "mobile_no":"9876543210",
    "worker_work_neighborhood":null,
    "worker_sms":"",
    "worker_Internet":null,
    "worker_background":null,
    "worker_location_name":null,
    "worker_tshirt":"",
    "forget_password_request":"0",
    "user_status":"1",
    "worker_task_type":null,
    "worker_birthdate":"0000-00-00",
    "worker_level":"0",
    "worker_first_name":"",
    "twitter_screen_name":"",
    "verify_email":"1",
    "profile_is_private":"0",
    "paypal_email":"ankit.rockersinfo@gmail.com",
    "email":"margee.test.rockersinfo@gmail.com",
    "tw_id":"",
    "worker_city":null,
    "last_name":"amin",
    "sign_up_ip":"1.22.81.187",
    "worker_id":"4",
    "worker_available_day":null,
    "worker_skills":null,
    "zip_code":"1234567",
    "worker_date":"2014-03-31 07:48:53",
    "worker_address":null,
    "worker_mobile":"",
    "worker_zipcode":null,
    "user_id":"4",
    "forget_password_code":null,
    "fb_id":"100007768140568",
    "sign_up_date":"2014-03-31 07:48:53",
    "profile_name":"khushi-a",
    "is_pro":"0",
    "worker_status":"1",
    "worker_transportation":null,
    "worker_interview_approved":"0",
    "worker_availability":null,
    "worker_email":"",
    "worker_available_time":null,
    "worker_background_approved":"0",
    "worker_devices":null,
    "worker_hear_about":null,
    "worker_last_name":"",
    "full_name":"Khushi amin"
    }],

    "task_assign_worker":"0",
    "user_location":0,
    "task_id":"75",
    "login":"false",

    "tast_start_day":["Today","Tomorrow","Sunday, May 04","Monday, May 05","Tuesday, May 06",
    "Wednesday, May 07","Thursday, May 08","Friday, May 09","Saturday, May 10","Sunday, May 11",
    "Monday, May 12","Tuesday, May 13","Wednesday, May 14","Thursday, May 15","Friday, May 16"],

    "tast_start_time":{
    "300":"5am",
    "840":"2pm",
    "1080":"6pm",
    "240":"4am",
    "1260":"9pm",
    "660":"11am",
    "960":"4pm",
    "1320":"10pm",
    "1380":"11pm",
    "360":"6am",
    "540":"9am",
    "1020":"5pm",
    "600":"10am",
    "180":"3am",
    "1200":"8pm",
    "480":"8am",
    "1140":"7pm",
    "1440":"midnight",
    "720":"noon",
    "120":"2am",
    "420":"7am",
    "900":"3pm",
    "60":"1am",
    "780":"1pm"},

    "task_detail":{
    "task_end_day":"0",
    "task_start_time":"0",
    "city_timezone":"-5",
    "extra_cost":"0.00",
    "state_id":"152",
    "task_accept":"0",
    "category_status":"1",
    "poster_agree":"0",
    "comming_soon":"0",
    "task_name":null,
    "task_status":"3",
    "task_assigned_date":"0000-00-00 00:00:00",
    "task_activity_status":"0",
    "category_name":"House Chore",
    "more_details":null,
    "category_image":"54880category_10.png",
    "active":"1",
    "category_url_name":"house-chore",
    "task_online":"0",
    "is_home":"1",
    "task_close_date":"0000-00-00 00:00:00",
    "city_name":"Acton",
    "how_to_pay":"2",
    "city_latitude":"43.633333",
    "task_id":"75",
    "task_price":"0.00",
    "task_is_private":"0",
    "city_longitude":"-80.033333",
    "worker_agree":"0",
    "city_id":"1764",
    "task_url_name":null,
    "user_id":"6",
    "task_post_date":"2014-05-02 00:09:32",
    "task_category_id":"1",
    "task_end_date":"0000-00-00",
    "country_id":"42",
    "task_start_date":"0000-00-00",
    "task_auto_assignment":"0",
    "category_description":"House Chore",
    "task_assing_worker":"0",
    "task_worker_id":"0",
    "task_city_id":"1764",
    "task_attachment":"",
    "task_complete_date":"0000-00-00 00:00:00",
    "task_end_time":"0",
    "task_description":null,
    "category_parent_id":"0",
    "category_average_price":"30",
    "task_start_day":"0",
    "task_ip":"210.89.56.198",
    "task_cancel_date":"0000-00-00 00:00:00"
    }

}

代码:

JSONObject abc = json.getJSONObject("tast_start_time");
Log.e("LOCATYION",json.getJSONArray("tast_start_day").toString());
Log.e("msg",abc.toString());
Log.e("msg",abc.getJSONObject("300").toString());

当我尝试记录jsonarray时,它的效果非常好,但是当我尝试获得300的jsonobject时,它会给我一个例外。

4 个答案:

答案 0 :(得分:1)

物业的价值" 300"不是JSON对象,它是一个字符串。尝试像

这样的东西
Log.e("msg",abc.getString("300"));

答案 1 :(得分:1)

JSON对象abc包含字符串条目" 5 am"在key" 300",而不是另一个JSON对象。所以它应该是:

Log.e("msg",abc.getString("300"));

答案 2 :(得分:1)

使用abc.getString("300");获取字符串值。

答案 3 :(得分:0)

你试图获取jsonobject,但它是一个json字符串,这就是你收到错误的原因。

Log.e("msg",abc.getJSONObject("300").toString());

以下替换

Log.e("msg",abc.getString("300"));

注意: -

1.   {} denote jsonobject

2.   [] denote jsonarray

3.    "value":"name" denote string