Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JAVA中将contentType text/html的HttpResponse转换为JSON_Java_Httprequest - Fatal编程技术网

如何在JAVA中将contentType text/html的HttpResponse转换为JSON

如何在JAVA中将contentType text/html的HttpResponse转换为JSON,java,httprequest,Java,Httprequest,下面是我从HttpRequest得到的响应。我想从SpringController将这个JSON响应返回到Ajax请求 ({ 'KUI': { code: '.KUI', indexDetailEnable: true, price: '20,650.21', netChange: '-13.01', percentChange: '-0.06%', tradeDate: '17/04/03',

下面是我从
HttpRequest
得到的响应。我想从SpringController将这个JSON响应返回到Ajax请求

({
   'KUI': {
       code: '.KUI',
       indexDetailEnable: true,
       price: '20,650.21',
       netChange: '-13.01',
       percentChange: '-0.06%',
       tradeDate: '17/04/03',
       tradeTime: '16:50',
       chartDate: '17/04/03',
       chartTime: '16:50'
    },

   'KUI': {
       code: '.NHK',
       indexDetailEnable: true,
       price: '--',
       netChange: '--',
       percentChange: '--%',
       tradeDate: '--/--/--',
       tradeTime: '--:--',
       chartDate: '17/04/03',
       chartTime: '17:15'
    },

    __end__: null
});

您可以使用org.json中的
新建JSONObject(yourResponse)
新建JSONArray(yourResponse)
,这已经在json中了,括号除外。@ciilthomas我试图使用jsonprettyprint打印,但打印为空。{“abc”:“abc”}我想这是json格式。@CicilThomas在打印之前我已经删除了()和分号。您到底想实现什么?在json中,名称/值对由一个字段名(双引号)组成,后跟一个冒号,后跟一个值(通过w3School)。上述响应的键未包含在“”中。那么,为什么上面的响应已经是JSON格式的呢?也许我错过了什么。