請教各位高手,如何讓android(client)端利用socket方式收到php server 來的JSON格式的資料? 小弟寫一個程式,希望從手機端android 利用名稱(shop_name)登入PHP server,建立socket連線後,如果PHP server 中資料庫中有shop_name相關資料有任何異動, 可以通知android ,但是現在android可連線PHP server ,卻卡在android無法收到PHP server來的JSON格式的資料?我為這問題困擾許久,請大大指點迷津, 說明: 1:有關PHP server 送JSON格式的程式碼 while($row_check=mysql_fetch_row($rows_check)) {$output[]=$row_check;} //將$row_check資料放到output sleep(1);if($output !=null){socket_write($connection,json_encode($output)); //回應資料} print_r($output);echo "\r\n"; $output[]=null; $row_check=null; 從螢幕上可以看到output的輸出為 Array([0]([0]=>30 [1]=>2015-01-10 [2]=>壹咖啡 ...) [1]([0]=>31 [1]=>2015-01-10 [2]=>7_eleven ...)) 那代表($output此變數是有值的,但是socket_write($connection,json_encode($output))這樣的寫法可以嗎?? 2:以下是要接收PHP server來的json 格式的資料,但是就是接收不到任何東西,請教大大該如何修改或可以給個方向 socket_connect_thread.sleep(10000); //等待10秒讓PHP server 丟資料過來 in.read(socket_t); //這裡in此變數需要做任何修改嗎? 如清空,或換另外變數來接收資料,因為in的值為空 String socket_recive = new String(new String(socket_t)); int bytesToRead; while(true){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(in)); while ((bytesToRead = socket_t.getInputStream().read(socket_buffer)) > 0) { Log.i("bytesToRead",bytesToRead+""); } br.close(); }catch(Exception e){ Log.e("log_tag json_convert", "Error converting result "+e.toString()); }
Recommended article: Chomsky: We Are All – Fill in the Blank. This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
You are receiving this email because you subscribed to this feed at blogtrottr.com.