JSONObject を受け入れるサーバーと、JSONObject をサーバーに送信する Android アプリがあります。問題は、サーバーが受け取る JSONObject の形式が気に入らないことです。誰が私が間違っているのか教えてもらえますか?
Android クライアント:
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();
}
そしてpythonサーバー:
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
Android のスタック トレースは次のとおりです。
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)