如何在android和node js之间发送和接收JSON格式的文件
我想使用socket将JSON格式的文件发送到express node js服务器,我不知道怎么做,我从android代码开始,但我不知道如何在服务器端获取它。以下是android代码:如何在android和node js之间发送和接收JSON格式的文件,android,json,node.js,sockets,express,Android,Json,Node.js,Sockets,Express,我想使用socket将JSON格式的文件发送到express node js服务器,我不知道怎么做,我从android代码开始,但我不知道如何在服务器端获取它。以下是android代码: package fr.learning_adventure.android.itac.model; import org.json.JSONException; import org.json.JSONObject; import java.io.Serializable; // Created
package fr.learning_adventure.android.itac.model;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
// Created by Moez on 02/03/16.
public class Learner implements Serializable{
private final static String JSON_PSEUDO = "pseudo";
private final static String JSON_MAC = "mac";
private String pseudo;
private String mac;
public Learner(String mac, String pseudo) {
this.pseudo = pseudo;
this.mac = mac;
}
public Learner(JSONObject object) {
try {
this.pseudo = object.getString(Learner.JSON_PSEUDO);
this.mac = null;
} catch (JSONException e) {
e.printStackTrace();
}
}
public String getPseudo() {
return this.pseudo;
}
public void setPseudo(String pseudo) {
this.pseudo = pseudo;
}
public JSONObject toJSON() {
JSONObject object = new JSONObject();
try {
object.putOpt(Learner.JSON_PSEUDO,this.pseudo);
object.putOpt(Learner.JSON_MAC, this.mac);
} catch (JSONException e) {
e.printStackTrace();
}
return object;
}
}
为什么不创建一个DTO类,其中包含要发送的信息,然后在您准备通过套接字调用发送对象时:
new Gson().toJson(DTO);
你的问题太宽了。。