在尝试从服务器转换JsonObject并将其转换为字符串时,我从上面收到此错误。我尝试接收的对象是{Type:“ ErrorMes”,Message:“ Error:'Type'”}},我可以正常接收和烘烤“ Type”,但是当我尝试使用“消息”,错误出现,这是我的代码:
mSocket.on("DevMessage", new Emitter.Listener() {
@Override
public void call(final Object... args) {
runOnUiThread(new Runnable() {
@Override
public void run() {
JSONObject obj = (JSONObject) args[0];
try {
String result1 = obj.getString("Message" );
Toast.makeText(MainActivity.this, result1, Toast.LENGTH_LONG).show();
//Toast.makeText(MainActivity.this, result2, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
mSocket.connect();
btnsend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = "Erromessage";
mSocket.emit("DevMessage",name);
}
});