WooCommerce API - 读取数据时获取 JsonParseException
WooCommerce API - Getting JsonParseException when reading data
我正在制作一个从 WordPress 页面获取订单的程序。
在多次测试中,下一段代码运行正常:
OAuthConfig config = new OAuthConfig(parameters.getUrl(), parameters.getConsumerKey(), parameters.getConsumerSecret());
WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V3);
Map<String, String> parametersOrders = new HashMap<>();
parametersOrders .put("per_page", "100");
parametersOrders .put("offset", "0");
List ordersCreated = wooCommerce.getAll(EndpointBaseType.ORDERS.getValue(), parametersOrders );
但现在在生产中我遇到了下一个错误:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.http.conn.EofSensorInputStream@56c43543; line: 1, column: 2]
显然,我正在读取 xml 对象而不是 json.
我该如何改变它?这是我想念的东西吗?
提前致谢...
编辑 1:
我第一次尝试这个,它工作正常:
订单检索成功。现在我收到了错误。
我跳过了参数部分;我正在从数据库中获取这些数据:
WooCommerceParameters parameters= GetWooCommerceParameters();
OAuthConfig config = new OAuthConfig(parameters.getUrl(), parameters.getConsumerKey(), parameters.getConsumerSecret());
消费者密钥和消费者秘密没问题,但是 URL 有这样的格式:
'https://test.com/store/'
并且必须是这样的:
'https://test.com/store'
没有最后的斜杠
我正在制作一个从 WordPress 页面获取订单的程序。
在多次测试中,下一段代码运行正常:
OAuthConfig config = new OAuthConfig(parameters.getUrl(), parameters.getConsumerKey(), parameters.getConsumerSecret());
WooCommerce wooCommerce = new WooCommerceAPI(config, ApiVersionType.V3);
Map<String, String> parametersOrders = new HashMap<>();
parametersOrders .put("per_page", "100");
parametersOrders .put("offset", "0");
List ordersCreated = wooCommerce.getAll(EndpointBaseType.ORDERS.getValue(), parametersOrders );
但现在在生产中我遇到了下一个错误:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.http.conn.EofSensorInputStream@56c43543; line: 1, column: 2]
显然,我正在读取 xml 对象而不是 json.
我该如何改变它?这是我想念的东西吗?
提前致谢...
编辑 1:
我第一次尝试这个,它工作正常:
订单检索成功。现在我收到了错误。
我跳过了参数部分;我正在从数据库中获取这些数据:
WooCommerceParameters parameters= GetWooCommerceParameters();
OAuthConfig config = new OAuthConfig(parameters.getUrl(), parameters.getConsumerKey(), parameters.getConsumerSecret());
消费者密钥和消费者秘密没问题,但是 URL 有这样的格式:
'https://test.com/store/'
并且必须是这样的:
'https://test.com/store'
没有最后的斜杠