这个问题可能以前曾被问过,但没有得到明确答复.如何在Retrofit请求的主体内发布原始整个JSON?
看到类似的问题在这里.或者这个答案是否正确,它必须是url编码形式并作为字段传递?我真的希望不会,因为我所连接的服务只是期待帖子正文中的原始JSON.它们未设置为查找JSON数据的特定字段.
我只是想与澄清这一restperts一劳永逸.一个人回答不使用Retrofit.另一个不确定语法.另一个人认为可以这样做,但只有当它的形式url编码并放在一个字段中时(在我的情况下这是不可接受的).不,我无法为我的Android客户端重新编码所有服务.是的,在主要项目中发布原始JSON而不是将JSON内容作为字段属性值传递是很常见的.让我们做对了,继续前进吧.有人可以指向显示如何完成此操作的文档或示例吗?或者提供可以/不应该完成的有效理由.
更新:我可以100%确定地说一件事.你可以在谷歌的排球中做到这一点.它是内置的.我们可以在Retrofit中做到这一点吗?
这个错误是什么?我怎样才能解决这个问题?我的应用正在运行,但无法加载数据.这是我的错误:使用JsonReader.setLenient(true)接受第1行第1列路径的格式错误的JSON $
这是我的片段:
public class news extends Fragment {
private RecyclerView recyclerView;
private ArrayList<Deatails> data;
private DataAdapter adapter;
private View myFragmentView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.news, container, false);
initViews();
return myFragmentView;
}
private void initViews() {
recyclerView = (RecyclerView) myFragmentView.findViewById(R.id.card_recycler_view);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
data = new ArrayList<Deatails>();
adapter = new DataAdapter(getActivity(), data);
recyclerView.setAdapter(adapter);
new Thread()
{
public void run()
{
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() { …
Run Code Online (Sandbox Code Playgroud) 完整的错误就是这个
错误:任务':app:transformClassesWithInstantRunForDebug'的执行失败.
java.lang.IllegalStateException:预期为BEGIN_ARRAY,但在第1行第1行为STRING路径$
我在Android Studio上对我的项目进行了一些小改动,尝试运行它并且它崩溃了我的PC,它完全冻结了几分钟,第一次在AS上编译时发生这种情况(我没有使用ADB)当我的电脑重启时,我收到错误
错误:条目中的空值:blameLogFolder = null
结果告诉我要删除我的项目的.gradle foldier,所以我这样做,当我再次运行它,我得到这个新的错误.
我不知道什么是错的,甚至不知道如何解决它,在线的额外帮助没有帮助.
10分钟前一切都工作得很好,现在项目不会编译,我甚至不能制作apk.
如何使用改造上传多个文件,
我尝试使用以下代码上传文件:
ApiService:
@Multipart
@POST("uploadData.php")
Call<ServerResponse> uploadFile(@Part MultipartBody.Part file,
@Part("name") RequestBody name,
@Part MultipartBody.Part img,
@Part("imgname") RequestBody imgname);
Run Code Online (Sandbox Code Playgroud)
和上传方法:
private void uploadFile() {
File file = new File(Environment.getExternalStorageDirectory() + "/Download/audio2.wav");
File file2 = new File(Environment.getExternalStorageDirectory() + "/Download/Salty.png");
RequestBody mFile = RequestBody.create(MediaType.parse("audio/*"), file);
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", file.getName(), mFile);
RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());
RequestBody mFile2 = RequestBody.create(MediaType.parse("image/*"), file2);
MultipartBody.Part fileToUpload2 = MultipartBody.Part.createFormData("file", file2.getName(), mFile2);
RequestBody filename2 = RequestBody.create(MediaType.parse("text/plain"), file2.getName());
ApiService uploadImage = ApiClient.getClient().create(ApiService.class);
Call<ServerResponse> fileUpload = uploadImage.uploadFile(fileToUpload, …
Run Code Online (Sandbox Code Playgroud) 我在邮递员上传递了更新用户请求并得到了成功的响应(见图),现在当我尝试在我的应用程序中使用 Retrofit 2 执行相同操作时,我收到错误为com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
. 有趣的是,我之前遇到过这个错误,我知道如果我的模型不符合响应,通常会发生这种情况。但这次我想我已经检查了所有的框,但还是出现了错误。如果有人能弄清楚我哪里出错了......
我在邮递员中的回应:
我的pojo:
package com.example.evidya.Retrofit.Model.EditModel;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class EditResponse {
@SerializedName("result")
@Expose
private String result;
@SerializedName("response_code")
@Expose
private Integer responseCode;
@SerializedName("msg")
@Expose
private String msg;
@SerializedName("data")
@Expose
private List<Object> data = null;
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public Integer getResponseCode() {
return responseCode;
}
public …
Run Code Online (Sandbox Code Playgroud)