2015-03-02 81 views
-2
{"result":"success","totalresults":2,"products":{"product":[{"pid":"1","gid":"1","type":"hostingaccount","name":"test1","description":"","module":"cpanel","paytype":"onetime","pricing":{"USD":{"prefix":"$","suffix":" USD","msetupfee":"0.00","qsetupfee":"0.00","ssetupfee":"0.00","asetupfee":"0.00","bsetupfee":"0.00","tsetupfee":"0.00","monthly":"0.00","quarterly":"0.00","semiannually":"0.00","annually":"-1.00","biennially":"-1.00","triennially":"-1.00"}},"customfields":{"customfield":[]},"configoptions":{"configoption":[]}},{"pid":"2","gid":"1","type":"other","name":"javad host","description":"","module":"","paytype":"recurring","pricing":{"USD":{"prefix":"$","suffix":" USD","msetupfee":"12.00","qsetupfee":"25.00","ssetupfee":"0.00","asetupfee":"0.00","bsetupfee":"0.00","tsetupfee":"0.00","monthly":"24.00","quarterly":"26.00","semiannually":"-1.00","annually":"-1.00","biennially":"-1.00","triennially":"-1.00"}},"customfields":{"customfield":[]},"configoptions":{"configoption":[]}}]}} 

這是我的JSON - 我收杆與此代碼:解析所有的JSON parametr和子集

<?php 
$url = 'http://safemode.acloud.ir/rasanegar/currencly.php'; 
$content = file_get_contents($url); 
$json = json_decode($content, true); 

foreach($json['products']['product']as $item) { 
echo '<tr>'; 
echo '<td>'.$item['pid'].'</td>'; 
echo '<td>'.$item['type'].'</td>'; 
echo '</tr>'; 
}?> 

,但我可以收杆產品JSON,像 'PID', 'GID',我不能收杆定價子集像「前綴」,「每月」

+0

'的foreach($項目[ '定價'] [ '美元']爲$ priceKey => $ priceValue){...}' – 2015-03-02 14:21:41

回答

0

爲什麼我們需要爲您調查數據結構?

動手做做看下次請:

{"result":"success", 
"totalresults":2, 
"products":{ 
    "product":[ 
     { 
      "pid":"1", 
      "gid":"1", 
      "type":"hostingaccount", 
      "name":"test1", 
      "description":"", 
      "module":"cpanel", 
      "paytype":"onetime", 
      "pricing":{ 
       "USD":{ 
        "prefix":"$", 
        "suffix":" USD", 
        "msetupfee":"0.00", 
        "qsetupfee":"0.00", 
        "ssetupfee":"0.00", 
        "asetupfee":"0.00", 
        "bsetupfee":"0.00", 
        "tsetupfee":"0.00", 
        "monthly":"0.00", 
        "quarterly":"0.00", 
        "semiannually":"0.00", 
        "annually":"-1.00", 
        "biennially":"-1.00", 
        "triennially":"-1.00" 
       } 
      }, 
      "customfields":{ 
       "customfield":[] 
      }, 
      "configoptions":{ 
       "configoption":[] 
      } 
     }, 
.... 

從而@MarkBaker在評論中寫道:

<?php 
$url = 'http://safemode.acloud.ir/rasanegar/currencly.php'; 
$content = file_get_contents($url); 
$json = json_decode($content, true); 

foreach($json['products']['product']as $item) { 
echo '<tr>'; 
echo '<td>'.$item['pid'].'</td>'; 
echo '<td>'.$item['type'].'</td>'; 
echo '<td>'.$item['pricing']['USD']['prefix'].'</td>'; 
echo '<td>'.$item['pricing']['USD']['monthly'].'</td>'; 
echo '</tr>'; 
}?> 
+0

坦克幫助 – 2015-03-02 16:02:46

+0

但我不強迫你回答我的問題 - 我只是需要幫助 - 如果你不想幫助我,下次不要幫助!但坦克幫助現在 – 2015-03-02 16:04:20