com.fasterxml.jackson.databind.exc.MismatchedInputException:意外的令牌(START_OBJECT),预期的START_ARRAY:

Sid*_*rth 5 android json ioexception jackson

我正在尝试保存SearchAvailableRidesRequestOffline到android Shared Preferences。我需要deserialise该对象以后才能使用它。当我尝试deserialise从中进行操作时json,出现了此异常。

IOException

com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class com.mnox.webservices.core.ARequest
 at [Source: (String)"{
  "request" : {
     .....
        "filterType"[truncated 882 chars]; line: 2, column: 15] (through reference chain: com.mnox.paymentgateway.commons.support.offline.SearchAvailableRidesRequestOffline["request"])
Run Code Online (Sandbox Code Playgroud)

JSON格式

{
  "request" : {
    //
    // SearchAvailableRidesRequest
    // Parameters
  },
  "concreateRequestClass" : "com.mnox.webservices.requests.v2.SearchAvailableRidesRequest",
  "currentActivity" : null,
  "maxLimitAllowed" : 1000,
  "priority" : 0,
  "requestType" : "mNoxSearch"
}
Run Code Online (Sandbox Code Playgroud)

爪哇

public class SearchAvailableRidesRequestOffline extends AOfflineRequest implements IModelRequestedController {

    public SearchAvailableRidesRequestOffline() {
    }

    public SearchAvailableRidesRequestOffline(SearchAvailableRidesRequest searchRequest) {
        super(searchRequest);
    }

    @Override
    public int getMaxLimitAllowed() {
        return 1000;
    }

    @Override
    public int getPriority() {
        return 0;
    }

    @Override
    public void onModelRequestCompleted(IModelRequestedController context, int modelIdentifier,
                                        Object modelData) {

    }

    @Override
    public RequestType getRequestType() {
        return RequestType.mNoxSearch;
    }


    @Override
    public Activity getCurrentActivity() {
        return null;
    }

    @Override
    public Class getConcreateRequestClass() { return SearchAvailableRidesRequest.class;} ;

}
public abstract class AOfflineRequest {

    public static enum RequestType { mNoxSearch, mNoxDriverCurrentLocation} ;

    private ARequest request;
    public AOfflineRequest(ARequest request) {
        this.request = request;
    }
    public void updatePreExecuteProgressBar() {

    }

    public void updatePostExecuteProgressBar() {

    }

    public abstract RequestType getRequestType() ;
    public abstract Class getConcreateRequestClass() ;
    public abstract int getMaxLimitAllowed();
    public abstract int getPriority();

    //
    // For gson
    //
    public AOfflineRequest() {
    }
    public ARequest getRequest() {
        return request;
    }
}
Run Code Online (Sandbox Code Playgroud)

Jor*_*sys 2

记住:

  • 如果 .json 内容以{开头,则被视为Json 对象

  • 如果 .json 内容以[开头,则被视为Json Array

你有这个错误

com.fasterxml.jackson.databind.exc.MismatchedInputException:意外的令牌(START_OBJECT),预期的START_ARRAY:

因为您期望一个 Json 数组,但您的响应是一个 Json 对象:

"{
  "request" : {
   ...
   ...
Run Code Online (Sandbox Code Playgroud)

检查你的回复。