当前位置: 首页 > 知识库问答 >
问题:

我从改装的BEGIN\u数组中得到一个错误响应,但在第1行第1列路径处是字符串$

宗政浩慨
2023-03-14

我已经看了好几个答案,我遗漏了一些东西。是否有办法在改装前查看数据并进行处理?

这是密码

extends Activity implements Callback<List<MemberPOJO>> {

@Inject
MembersInterface memberInterfaceService;

@Override
public void onFailure(Exception ex) {

    setProgressBarIndeterminateVisibility(false);

    String retrofitError = "Error: " + ex.getMessage();

    Log.e("LoadActivity", retrofitError);
}

@Override
public void onSuccess(List<MemberPOJO> result) {

    ArrayList<String> strings = new ArrayList<String>(result.size());

    Log.e("LoadActivity", "MemberPOJO:" + result);

}

...

public void getMemberHostData() {
    MemberLoader loader = new MemberLoader(this, memberInterfaceService);

    RetrofitLoaderManager.init(getLoaderManager(), 0, loader, this);
}

static class MemberLoader extends RetrofitLoader<List<MemberPOJO>, MembersInterface> {

    public MemberLoader(Context context, MembersInterface service) {

        super(context, service);
    }



    RestAdapter.Builder builder= new RestAdapter.Builder()
            .setRequestInterceptor(new RequestInterceptor() {
                @Override
                public void intercept(RequestFacade request) {
                    request.addHeader("Accept", "application/json;versions=1");
                    request.addHeader("authorization",getAuthorization(getContext()));

                }
            });

    @Override
    public List<MemberPOJO> call(MembersInterface service) {

        return service.listOfMemebers();
    }
}

共有1个答案

何章横
2023-03-14

如果您有StringConverter和StringTypeOutput,您可以拉字符串。这将提供纯字符串,并且不会反序列化任何内容。当然,您可以尝试在frombody()方法中验证JSON是否有效,如果它有效,则继续反序列化(将其扩展到GsonConverter),否则只需获取响应

public class StringConverter implements Converter {

    @Override
    public Object fromBody(TypedInput arg0, Type arg1)
            throws ConversionException {

        return getStringFromInputStream(arg0.in());
    }

    @Override
    public TypedOutput toBody(Object arg0) {
        String string = (String) arg0;
        return new StringTypedOutput(string.getBytes(Charset.forName(HTTP.UTF_8)));
    }


    public static String getStringFromInputStream(InputStream is) {

    BufferedReader br = null;
    StringBuilder sb = new StringBuilder();

    String line;
    try {

        br = new BufferedReader(new InputStreamReader(is));
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        //close the stream if needed.
    }

    return sb.toString();

}
}
 类似资料: