意外字符('F'(代码 70)):需要一个有效值(数字、字符串、数组、对象、'true'、'false' 或 'null')这是什么意思?

问题描述 投票:0回答:2

我正在尝试使用休息客户端访问网址

我的客户代码:

 public class ProductByListTestClient {

//  private final String USER_AGENT = "Mozilla/5.0";

public static void main(String[] args) {

    ProductByListTestClient http = new ProductByListTestClient();
    try {
        http.sendPost();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

// HTTP POST request
private void sendPost() throws Exception {

    String url = "http://localhost:7111/product.lookup.tobuylist/rest/product/productbuylist";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("POST");
    con.setDoOutput(true);
   // con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Accept", "application/json");
    con.setRequestProperty("Content-Type", "application/json");
    String urlParameters = "{\"itemID\":F123}";

    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'POST' request to URL : " + url);
    System.out.println("Post parameters : " + urlParameters);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(new InputStreamReader(
            con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    // print result
    System.out.println(response.toString());

}

}

ServletException
的根本原因:

org.codehaus.jackson.JsonParseException: Unexpected character ('F' (code 70)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: weblogic.servlet.internal.ServletInputStreamImpl@186948; line: 1, column: 12]
    at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432)
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
    at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)
    at org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:2084)
    at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:549)
    Truncated. see log file for complete stacktrace
java rest
2个回答
1
投票

这是因为使用客户端在 URL 上发送了错误的 JSON 格式。 只需检查您尝试通过 URL 发送的 JSON 数据。如果您收到此类异常“意外字符('F'(代码 70)):预期有效值”。 然后你只需确保数据采用正确的 JSON 格式即可!


0
投票

您正在传递一个布尔值作为 False,它应该是 false 而不是(小写)

© www.soinside.com 2019 - 2024. All rights reserved.