2016-03-24 37 views
-1

arasında JSON içinde dosya göndermek ve almak için soket kullanarak bir ekspres node js sunucuya JSON dosyaları göndermek istiyorum, nasıl yapılacağını bilmiyorum, android kodu ile başladım, ama Sunucu tarafında nasıl elde edeceğimi bilmiyorum.android ve node js

new Gson().toJson(DTO); 

What is Data Transfer Object DTO

Gson user guide:

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; 
    } 


} 
+0

Sorunuz çok geniştir .. –

cevap

0

Neden soket çağrı yoluyla nesneyi göndermek üzereyken sonra göndermek ve bilgileri içeren bir DTO sınıf oluşturmak değil: Burada android koddur