我需要将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是一个字符串。当我在服务器中发送telo时,我得到了:

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


问题在于,正文中应该出现json对象,并出现类似地址存储器的内容

我该如何解决?

坦斯克

[编辑]

我更新帖子。.我使用Gozirra API发送Json对象(实际上是一个字符串),它允许使用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本身

10-07 19:41
查看更多