简体   繁体   English

尝试发送时,Android JSONObject变为null

[英]Android JSONObject becomes null when trying to send

When I'm trying to push a JSONObject over a data stream, and I've built the JSONObject properly, but then I try and publish it to the stream it is null. 当我尝试将JSONObject推入数据流时,并且已经正确构建了JSONObject ,但是随后我尝试将其发布到流中,因此它为null。

JSONObject position = new JSONObject();

        try {
            position.put("lat", location.getLatitude());
            position.put("lng", location.getLongitude());
        } catch (JSONException e) {
            System.out.println("json not work");
            e.printStackTrace();
        }
        System.out.println(position) //result: {"lat":37,"lng":-122}
        pubNub.publish().message(position)//never sent, if other type it works

尝试pubNub.publish().message(position.toString());

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

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