gpt4 book ai didi

java.lang.String 无法转换为 JSONObject

转载 作者:行者123 更新时间:2023-12-01 15:07:11 24 4
gpt4 key购买 nike

在我的 Android 应用程序中,我调用一个 Web 服务,它返回一个 jsonobject。在设备中,我得到这样的一个响应..

"{  \"Time_Stamp\" : \"10/10/2012 4:26 PM\",  \"records\" : [ {    \"'Name'\" : \"'LD-00000002'\",    \"'Appointment_Date_Time'\" : \"'null'\",    \"'Phone'\" : \"'9909955555'\",    \"'Home_Country_Address'\" : \"'null'\",    \"'Occupation'\" : \"'null'\",    \"'SR_Appointment_Status'\" : \"'Open'\",    \"'Id'\" : \"'a0OE0000001iLynMAE'\",    \"'SR_Appointment_Comment'\" : \"'testing'\",    \"'ProductsOfInterest'\" : \"'null'\",    \"'ActivityName'\" : \"'Sales'\",    \"documentsList\" : [ ]  }, {    \"'Name'\" : \"'LD-00000002'\",    \"'Appointment_Date_Time'\" : \"'null'\",    \"'Phone'\" : \"'9909955555'\",    \"'Home_Country_Address'\" : \"'null'\",    \"'Occupation'\" : \"'null'\",    \"'SR_Appointment_Status'\" : \"'Open'\",    \"'Id'\" : \"'a0OE0000001iLynMAE'\",    \"'SR_Appointment_Comment'\" : \"'testing'\",    \"'ProductsOfInterest'\" : \"'null'\",    \"'ActivityName'\" : \"'Sales'\",    \"documentsList\" : [ {      \"numberOfImages\" : 3,      \"Name\" : \"new document\",      \"Mandatory\" : false,      \"FilePath\" : null,      \"Category\" : null    } ]  } ]}"

我尝试将其转换为这样的对象

  JSONObject jsonObj=new JSONObject(objMngr.getResponse());

在转换它时抛出一个异常“java.lang.String无法转换为JSONObject”...下面是它抛出的确切异常..原因是什么以及如何解决这个问题??

 {  "Time_Stamp" : "10/10/2012 4:26 PM",  "records" : [ {    "'Name'" : "'LD-00000002'",    "'Appointment_Date_Time'" : "'null'",    "'Phone'" : "'9909955555'",    "'Home_Country_Address'" : "'null'",    "'Occupation'" : "'null'",    "'SR_Appointment_Status'" : "'Open'",    "'Id'" : "'a0OE0000001iLynMAE'",    "'SR_Appointment_Comment'" : "'testing'",    "'ProductsOfInterest'" : "'null'",    "'ActivityName'" : "'Sales'",    "documentsList" : [ ]  }, {    "'Name'" : "'LD-00000002'",    "'Appointment_Date_Time'" : "'null'",    "'Phone'" : "'9909955555'",    "'Home_Country_Address'" : "'null'",    "'Occupation'" : "'null'",    "'SR_Appointment_Status'" : "'Open'",    "'Id'" : "'a0OE0000001iLynMAE'",    "'SR_Appointment_Comment'" : "'testing'",    "'ProductsOfInterest'" : "'null'",    "'ActivityName'" : "'Sales'",    "documentsList" : [ {      "numberOfImages" : 3,      "Name" : "new document",      "Mandatory" : false,      "FilePath" : null,      "Category" : null    } ]  } ]} of type java.lang.String cannot be converted to JSONObject

最佳答案

尝试

  JSONObject jsonObj=new JSONObject(objMngr.getResponse().toString().replace("\\", " "));

你的 jsonString 看起来没问题。但是您的响应类型可能不是字符串。尝试一下。问题在于服务器发送的已转义的引号。

关于java.lang.String 无法转换为 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12818073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com