如何在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格式的呢?也许我错过了什么。