  | 
              
	              
	                
  
    
	 
        ช่วยด้วยครับ ผมรับขอมูลมา แต่ต้องการให้แสดงแค่บางส่วน ทำใงครับ มีโค้ชให้ ครับ     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                <?php 
$user="your_user";  
$pass="your_pass";  
$url="http://localhost/login";  
 
$postdata = "email=".$user."&password=".$pass;  
 
$ch = curl_init();  
curl_setopt ($ch, CURLOPT_URL, $url);  
curl_setopt ($ch, CURLOPT_HTTPHEADER,$header); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);  
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);  
curl_setopt ($ch, CURLOPT_USERAGENT,'okhttp/3.8.0'); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);    
curl_setopt ($ch, CURLOPT_REFERER, $url);  
 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);  
curl_setopt ($ch, CURLOPT_POST, 1);  
$result = curl_exec($ch); 
 
$aa = $result; 
echo $aa; 
 
?> 
 
ผมส่งข้อมูลไปแล้วได้รับค่าเป็นแบบนี้ 
 
{"data":{"id":"123456789"}} 
 
ซึ่ง ผมต้องการให้แสดงแค่ 123456789 ออกสู่หน้าจอ ทำใงครับ 
 
      
 
 
  Tag : PHP               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2019-02-11 11:54:33 | 
                      By :
                          sujinda | 
                      View :
                          931 | 
                      Reply :
                          7 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 1.ข้อมูลที่ออกมามันเป็นแบบ json หรือป่าวครับ 
2.มันเป็นข้อมูลที่มีรูปแบบเป็น array หรือป่าวครับ 
 
ตัวนี้ผมลองทำครับ 
Code (PHP) 
<?php
// Read JSON Decode
$jsonCode = '{"id":"123456789"}';
$jsonDecode = json_decode($jsonCode, true);
    echo $jsonDecode['id']."<br/>";
	
?>
 
 
ศึกษาจากตัวนี้ครับ 
https://www.thaicreate.com/community/php-mysqli-json.html                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2019-02-11 15:30:58              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-02-11 15:30:08 | 
                        By :
                            nobetaking | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 1 เขียนโดย : nobetaking เมื่อวันที่ 2019-02-11 15:30:08 
รายละเอียดของการตอบ ::
  ไม่มีอะไรขึ้นเลยครับ 
 
นอกจาก คำว่า Array ออกสู่หน้าจอ
 
ข้อมูลไม่แสดงครับ
 
โค้ชที่เพิ่มไป
 Code (PHP)
<?php
$user="your_user"; 
$pass="your_pass"; 
$url="http://localhost/login"; 
$postdata = "email=".$user."&password=".$pass; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_USERAGENT,'okhttp/3.8.0');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch);
$aa = $result;
// Read JSON Decode
$jsonCode = $aa;
$jsonDecode = json_decode($jsonCode, true);
echo $jsonDecode;
?>
 
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-02-11 21:59:53 | 
                        By :
                            sujinda | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ใช้ตัวแปรเปลืองไปหรือเปล่า 
Code (PHP) 
$result = curl_exec($ch);
$aa = json_decode( $result);
print_r($aa);
  
 
 
คำสั่ง echo มันใช้กับ ตัวแปร ปกติเท่านั้น ถ้าต้องการ echo object ต้องใช้ คำสั่งอื่นช่วย หรืออ้างอิง element แบบ object                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-02-11 22:09:29 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองเขียน 
 
Code (PHP) 
$result = curl_exec($ch);
$aa = json_decode( $result);
$var = print_r($aa,true);
echo $var["data"];
  
 
stdClass Object ( [data] => stdClass Object ( [ssid] => e607e06dfccf39f31d2254628e3709c6 ) ) 
 
มันน่าจะแสดง stdClass Object ( [ssid] => e607e06dfccf39f31d2254628e3709c6 ) 
 
แต่มันแสดงแค่ s ตัวแรกครับ แก้ยังใงดีครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-02-11 22:56:12 | 
                        By :
                            sujinda | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เย้ยยยยยยยยยยยยยยยยยย 
ได้แล้วววววววววววววววววว 
 
$result = curl_exec($ch); 
$aa = json_decode($result,true)['data']['id']; 
print_r($aa); 
 
ขอบคุณทุกท่านนะครับ ไว้โอกาศหน้ามีปัญหสอีกจะมากถามใหม่น้าาาาาาาาาาาาาาาครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-02-11 23:18:12 | 
                        By :
                            sujinda | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองเขียนแบบ oop ดูนะครับ คือเบสคลาส ก็คือ oop วิธีเขียนอ้างอิง ใช้ -> ชื่อelement 
 
$aa = json_decode($result,true)->data->id;                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-02-12 08:35:17 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |