Note that there are some explanatory texts on larger screens.

plurals
  1. POSending JSONObject from Android to Python
    primarykey
    data
    text
    <p>I have a server that accepts a JSONObject and an Android app that sends a JSONObject to the server. The problem is that the server doesn't like the format of the JSONObject it receives. Can anyone tell me what I'm doing wrong?</p> <p>Android Client:</p> <pre><code>try{ Socket s = new Socket("67.194.98.244",13375); ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream()); org.json.JSONObject json = new org.json.JSONObject(); json.put("order", id); oos.writeObject(json); oos.flush(); oos.close(); }catch(Exception e){ e.printStackTrace(); } </code></pre> <p>And the python server:</p> <pre><code>class MyTCPServerHandler(SocketServer.BaseRequestHandler): def handle(self): try: data = json.loads(self.request.recv(1024).strip()) # process the data, i.e. print it: for key, value in data.iteritems(): with print_lock: print key, value if key == 'order': SubmitOrder(value,self) elif key == 'status': getStatus(value,self) else: with print_lock: print "no order" except Exception, e: print "Exception while receiving message: ", e </code></pre> <p>And here's the stack trace on Android:</p> <pre><code>09-21 21:53:49.804: W/System.err(27827): java.io.StreamCorruptedException 09-21 21:53:49.804: W/System.err(27827): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1528) 09-21 21:53:49.804: W/System.err(27827): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481) 09-21 21:53:49.804: W/System.err(27827): at com.austinn.hamster.Print.sendCommand(Print.java:173) 09-21 21:53:49.804: W/System.err(27827): at com.austinn.hamster.Print$1$1.run(Print.java:92) 09-21 21:53:52.144: W/System.err(27827): java.io.StreamCorruptedException 09-21 21:53:52.144: W/System.err(27827): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1528) 09-21 21:53:52.154: W/System.err(27827): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481) 09-21 21:53:52.154: W/System.err(27827): at com.austinn.hamster.Print.sendCommand(Print.java:173) 09-21 21:53:52.154: W/System.err(27827): at com.austinn.hamster.Print$1$1.run(Print.java:92) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload