2015-03-02 38 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