【问题标题】:Get the data from the JsonArray [duplicate]从 JsonArray 中获取数据 [重复]
【发布时间】:2017-09-12 09:18:33
【问题描述】:

这是我打印日志时的 JSON 结果。我无法从此结果中获取数据。请建议如何从该结果中获取数据。错误显示 org.json.JSONArray 类型的无法转换为 JSONObject。我知道已经有很多与此相关的帖子,但我不明白如何获取数据。

09-12 05:12:57.606: W/System.err(3385): org.json.JSONException: Value 
[
  {
    "client": [
      {
        "office_name": "",
        "is_verified": "1",
        "forum_email_notification": "1",
        "city": "",
        "first_name": "Pratik",
        "balance": "0",
        "option_domain_name": "Vision",
        "initials": "Mr",
        "client_type": "0",
        "group_credit": "0.00",
        "gender": "0",
        "is_approved": "1",
        "domain_name": "Vision",
        "client_id": "2",
        "otherim": "",
        "credit": "0.00",
        "is_spam": "0",
        "office_phone": "",
        "parent_id": "0",
        "domain_url": "http://example.com/vision4/sandip/v5/",
        "fax": "",
        "forum_signature_content": "",
        "group_id": "1",
        "optionB_domain_id": "1",
        "country": "",
        "contact_number": "",
        "user_name": "test",
        "email": "pratik@test.com",
        "job_title": "",
        "last_name": "T",
        "parent_name": "",
        "temporary_address": "",
        "facebook_id": "",
        "language": "1",
        "office_contact_num": "",
        "salt": "e2e838b89b16f488a901b3b364ad839e",
        "zip_code": "",
        "office_website": "",
        "department": "",
        "state": "",
        "office_fax": "",
        "login_as": "0",
        "currency": "USD",
        "permanent_address": "",
        "department_access": "0",
        "is_manager": "0",
        "birthdate": "",
        "registration_date": "1504254310",
        "parent_email": "",
        "password_auth": "0",
        "group_name": "Default",
        "netmeetingid": "",
        "website": "",
        "domain_id": "1",
        "is_banned": "0",
        "twitter_id": "",
        "mobile_number": "",
        "office_address": "",
        "authentication": "383Y4A==",
        "harvest_id": "0",
        "image_path": "",
        "office_email": ""
      }
    ],
    "unsolve": 3,
    "solve": 0
  }
]
of type org.json.JSONArray cannot be converted to JSONObject

【问题讨论】:

  • 您如何尝试从您的 json 字符串中获取数据? (请在此处添加代码)
  • 到目前为止你做了什么?

标签: android


【解决方案1】:

这是因为您的结果是 JSONObject 数组,而不是 JSONObject 本身

【讨论】:

  • 是的本杰明,但我是 android 新手。
  • 问题通过以下解决方案得到解决。字符串结果 =client_array.toString();尝试 { JSONArray jsonArray = new JSONArray(result); JSONObject 实际数据 = jsonArray.getJSONObject(0); JSONObject 响应 = actualData.getJSONObject("client");字符串 fname=response.getString(FIRST_NAME);
猜你喜欢
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-20
  • 1970-01-01
相关资源
最近更新 更多