我正在尝试将 SearchAvailableRidesRequestOffline
保存到 android Shared Preferences
。我需要反序列化
对象以便稍后使用它。当我尝试从 json
对其进行反序列化
时,出现了此异常。
IO异常
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"])
JSON
{
"request" : {
//
// SearchAvailableRidesRequest
// Parameters
},
"concreateRequestClass" : "com.mnox.webservices.requests.v2.SearchAvailableRidesRequest",
"currentActivity" : null,
"maxLimitAllowed" : 1000,
"priority" : 0,
"requestType" : "mNoxSearch"
}
Java
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;
}
}
最佳答案
记住:
if the .json content starts with { is considered as a Json Object.
if the .json content starts with [ is considered as a Json Array.
你有这个错误
com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY:
因为您期待一个 Json 数组,但您的响应是一个 Json 对象:
"{
"request" : {
...
...
检查您的回复。
关于android - com.fasterxml.jackson.databind.exc.MismatchedInputException : Unexpected token (START_OBJECT), 预期 START_ARRAY:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49822202/