resp=callApi(protocol+"://"+host+":"+"5443"+"/webhook/tokens/",HttpOp.POST,
ContentType.JSON, credentials.toString(), headers(headers));
String resp_body = EntityUtils.toString(resp.getEntity());
JSONObject jsobj = new JSONObject(resp_body);
这是抛出异常:org.json.JSONException:JSONObject文本必须以字符1中的“{”开头
因为resp_body如下所示:
"{\"auth\":{\"token\":{\"id\":\"eyJ0eXAiOiJKV1MiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyY2NkYTM4NzViNjFlODMyMDE1YjYxZTg2YjFjMDAzOCIsInJlZnJlc2hfdG9rZW4iOiJTRWU3TURxL0twM1pQcFhNa2lHSTFNYzArN3p1RlFMdjJPb3oxS0xrd3JpdUMwblc4R3dkV1RNdHlqY2d0TVg3c3R4VXZ0V3Nxd3NNMzlLaGRvWDZmemErdUZYTVloaFk3L29ZREk2YUdyVEhCWk1uNDFVbXpXU2NKTGE2Qno3M0Q0VUc4MDlmSHZ0OHFSOG1ON1BPSkEyc1Y0STRnRXp6NW5WdXcrbTQ2ZWp1MTJ6YVpGUWVrc2ZObDBTcWFXYjRXNEp2N1I5TVNCMUZtZnNIRkZCc2hUcEEwYmRjZkZ0M0szNHgwOCtFcWorajlFMENRN2hXU3Brck85OW1ld2s5REQrSkFSU2h2MEpuc21CSFp0clBqdTE5cTIwUUl6cU5RS21uY2o3b3VKZ0tmbUNSdVMzN04rZFBldnRFNmlQWEhRQ3NMWjFUNzYwemRFOVV4dis0TGxqWWJCb0liOTJya0xVdXc5S3hlbDRXZ1dlbnRLa0FuaXd0RXovMzM0TGdTdllxVlFTc3dhVlIzVzJ3UHdIRStob0FWd1hUOEN5SFBqU0xNa1JDa045OUJsaElBY1BsUXRiZ0FodTFMSHo5SlZKMnRKNk1HV2NoZ3gzdXdqeEFBZz09IiwiaXNzIjoiSWRNIDEuMTUuMiIsImNvbS5ocGUuaWRtOnRydXN0b3IiOm51bGwsImV4cCI6MTQ5MjE3NDk3OSwiY29tLmhwLmNsb3VkOnRlbmFudCI6eyJpZCI6IjJjY2RhMzg3NWI2MWU4MzIwMTViNjFlODVlMWIwMDE3IiwibmFtZSI6ImNvcmUiLCJkZXNjcmlwdGlvbiI6IkNvbnN1bWVyIiwiZW5hYmxlZCI6dHJ1ZX0sInBybiI6ImFkbWluIiwiaWF0IjoxNDkyMTczMTc5LCJqdGkiOiIzZjIyNmEwMS05YzNjLTRiNjItYTA3NC1iNWY2ZTgwYTYzYzkifQ.4KX2mRj3DYUvciEc8ZSN_YA18oirkmPIKOX5RpMR36c\",\"issued_at\":\"2017-04-14T12:32:59.021Z\",\"expires\":\"2017-04-14T13:02:59.000Z\",\"tenant\":{\"id\":\"2ccda3875b61e832015b61e85e1b0017\",\"name\":\"core\",\"description\":\"Consumer\",\"enabled\":true}},\"user\":{\"username\":\"admin\",\"id\":\"2ccda3875b61e832015b61e86b1c0038\",\"name\":\"admin\",\"groups\":[{\"id\":\"propel_users_group_id\",\"name\":\"propel-users\",\"displayName\":\"Propel Users\",\"metadata\":{},\"roles\":[]},{\"id\":\"2ccda3875b61e832015b61e861b60031\",\"name\":\"Administrators\",\"displayName\":\"Administrators\",\"groupInfo\":\"Administrators group\",\"metadata\":{\"description\":\"Administrators group\"},\"roles\":[]}],\"roles\":[{\"id\":\"2ccda3875b61e832015b61e85ee5002d\",\"locked\":false,\"type\":\"CONSUMER\",\"description\":\"admin for management portal\",\"integration\":true,\"application\":\"com.hpe.tenant1\",\"name\":\"MNG_ADMIN\",\"displayName\":\"management portal admin\"},{\"id\":\"6268FD06A0123C62BB911D7541B2CFA8\",\"locked\":true,\"type\":\"CONSUMER\",\"description\":\"Performs IdM administration for consumer organization\",\"application\":\"IdM\",\"name\":\"IDM_ADMIN\",\"displayName\":\"Organization IdM Administrator\"}],\"profile\":{\"displayName\":\"Admin\",\"userEmail\":\"admin@userEmail.com\",\"common_name\":\"admin_common\",\"email\":\"admin@email.com\",\"username\":\"admin\"}},\"refreshToken\":\"SEe7MDq/Kp3ZPpXMkiGI1Mc0+7zuFQLv2Ooz1KLkwriuC0nW8GwdWTMtyjcgtMX7stxUvtWsqwsM39KhdoX6fza+uFXMYhhY7/oYDI6aGrTHBZMn41UmzWScJLa6Bz73D4UG809fHvt8qR8mN7POJA2sV4I4gEzz5nVuw+m46eju12zaZFQeksfNl0SqaWb4W4Jv7R9MSB1FmfsHFFBshTpA0bdcfFt3K34x08+Eqj+j9E0CQ7hWSpkrO99mewk9DD+JARShv0JnsmBHZtrPju19q20QIzqNQKmncj7ouJgKfmCRuS37N+dPevtE6iPXHQCsLZ1T760zdE9Uxv+4LljYbBoIb92rkLUuw9Kxel4WgWentKkAniwtEz/334LgSvYqVQSswaVR3W2wPwHE+hoAVwXT8CyHPjSLMkRCkN99BlhIAcPlQtbgAhu1LHz9JVJ2tJ6MGWchgx3uwjxAAg==\"},\"extInfo\":{\"suiteInstallerUrl\":\"https://sag-rh72-hcm1.csacloud.local:5443/suiteInstaller/suite-installer.html\",\"csrfToken\":\"bb11e5f5f826d1fdf32d9e50bfe4e1f4\",\"passwordChangedStatus\":1}}"
答案 0 :(得分:0)
您应该在开始和结束时删除(")
,并在解析为 JSON 之前删除响应中的所有(\")