Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android和node js之间发送和接收JSON格式的文件_Android_Json_Node.js_Sockets_Express - Fatal编程技术网

如何在android和node js之间发送和接收JSON格式的文件

如何在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

我想使用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 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);


你的问题太宽了。。