gpt4 book ai didi

java - 找不到类型为 : class org. json.JSONArray 的返回值的转换器

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:39:49 24 4
gpt4 key购买 nike

我想从 spring Controller 方法返回一个 JSONArray(org.json.jar) 对象,这是我的 java spring Controller :

import org.json.JSONArray;
import org.json.JSONException;

@RestController
public class BICOntroller{

@RequestMapping(value="/getStatus", method = RequestMethod.GET)
public ResponseEntity<JSONArray> getStatus() throws JSONException{
ResponseEntity<JSONArray> response = null;
JSONArray arr = new JSONArray();

JSONObject obj = new JSONObject();
//process data
arr.put(obj);

response = new ResponseEntity<JSONArray>(arr, HttpStatus.OK);
return response;
}

}

Angular js 调用:

            $http({
url: 'getStatus',
method: 'GET',
responseType: 'json'
}).then(function(response){
console.log(response);
return response;
}, function(error){
console.log(error);
return error;
});

这会产生 500 错误:

java.lang.IllegalArgumentException: No converter found for return value of type: class org.json.JSONArray

我在类路径中包含了 jackson-core-2.7.5.jarjackson-databind-2.7.5.jar

谢谢!

最佳答案

添加依赖项对我不起作用。起作用的是将 JSONArray 转换为字符串。仅供引用,我正在使用 Spring Boot 应用程序并试图返回一个 JSONArray。

关于java - 找不到类型为 : class org. json.JSONArray 的返回值的转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43984871/

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