繁体   English   中英

将JSON发送到服务器

[英]Send JSON to server

我需要将JSON对象作为String发送到我的服务器,我这样做:

json.put("TYPE", "1");
            json.put("CODE", "0");
            json.put("NODEID", id);
            json.put("TSTAMP", mtemporal);
            json.put("XPOS", lastx);
            json.put("YPOS", lasty);
            json.put("HDOP", "");
         telo=json.toString();

telo是一个String。 当我在服务器上发送telo时,我得到了这个:

Object {command: "MESSAGE", headers: Object, body: "[Ljava.lang.String;@429106c0", id: undefined, receipt: undefined…}

问题是在body中应该出现json对象并出现类似地址的内存

我怎么解决呢?

Thansk

[编辑]

我更新帖子..我发送Json对象,真的是一个字符串,使用Gozirra API,允许连接并使用STOMP协议将数据发送到activemq服务器

更多代码:

public void send(float lastx,float lasty,String id,String mtemporal) {


        try {
            json.put("TYPE", "1");
            json.put("CODE", "0");
            json.put("NODEID", id);
            json.put("TSTAMP", mtemporal);
            json.put("XPOS", lastx);
            json.put("YPOS", lasty);
            json.put("HDOP", "");
         telo=json.toString();
        } 
        catch (JSONException e) {
            e.printStackTrace();
        }

        new Send().execute(telo);

    }


public class Send extends AsyncTask<String, Void, Void> {

    @Override
    protected Void doInBackground(String... params) {
        Log.i("telo", "estoy para enviar");
        c.begin();
        c.send("/topic/LOCATIONJSON", String.valueOf(params));
        c.commit();
        return null;
    }

}

String.valueOf(params)应该是String.valueOf(params[0])它给你一个地址内存,因为你代表一个String数组,而不是String本身

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM