douhong9210
2015-06-24 18:53
浏览 39
已采纳

如何从内容中获取价值? [关闭]

{"prereqs":{"prereq":{"type":"prereq_check","value":"submerging_island_feature_enabled"}},"divisions":{"division":[{"items":{"item":[{"name":"rhino_shell","rarity":"common"},{"name":"walrus_wavy","rarity":"special"},{"name":"hippo_fancyshell","rarity":"rare"},{"name":"rhino_jellyfish","rarity":"superRare"}]},"name":"rubyCount_30"},{"items":{"item":[{"name":"walrus_clam","rarity":"common"},{"name":"hippo_nautical","rarity":"special"},{"name":"giraffe_coral","rarity":"rare"},{"name":"elephant_starburst","rarity":"superRare"}]},"name":"rubyCount_40"},{"items":{"item":[{"name":"giraffe_waverider","rarity":"common"},{"name":"pony_sea","rarity":"special"},{"name":"magicdeer_seadeer","rarity":"rare"},{"name":"pony_seaprincesscorn","rarity":"superRare"}]},"name":"rubyCount_50"},{"items":{"item":[{"name":"bigcat_crystallion","rarity":"common"},{"name":"magicdeer_midnightdeer","rarity":"special"},{"name":"horse_ofthesea","rarity":"rare"},{"name":"horse_wingedsea","rarity":"superRare"}]},"name":"rubyCount_60"}]},"crafting":{"recipes":{"recipe":[{"name":"qdke"},{"name":"sb1p"},{"name":"cb8v"}]}},"listEndDate":"07/13/2015","currencyItem":{"name":"healingpotionbottle"},"feed":{"throttleTime":"21600"},"name":"submerging_island"}

图片转代码服务由CSDN问答提供 功能建议

{“prereqs”:{“prereq”:{“type”:“prereq_check”,“value”:“ submerging_island_feature_enabled “},” 分裂 “:{” 师 “:[{” 项目 “:{” 项目 “:[{” Name “:” rhino_shell “ ”稀罕物“: ”普通“},{ ”名“:” walrus_wavy”, “稀罕物”: “特殊”},{ “名”: “hippo_fancyshell”, “稀罕物”: “罕见”},{ “名”: “rhino_jellyfish”, “稀罕物”: “superRare”}]}, “名”: “rubyCount_30”},{ “项目”:{ “项目”:[{ “Name”: “walrus_clam”, “稀罕物”: “普通”},{ “名”: “hippo_nautical”, “稀有” : “特殊”},{ “名”: “giraffe_coral”, “稀罕物”: “罕见”},{ “名”: “elephant_starburst”, “稀罕物”: “superRare”}]}, “名”:“rubyCount_40 “},{” 项目 “:{” 项目 “:[{” Name “:” giraffe_waverider”, “稀罕物”: “普通”},{ “名”: “pony_sea”, “稀罕物”: “特殊”}, { “名”: “magicdeer_seadeer”, “稀罕物”: “罕见”},{ “名”: “pony_seaprincesscorn”, “稀罕物”: “superRare”}]}, “名”: “rubyCount_50”},{“项目 “:{” 项目 “:[{” Name “:” bigcat_crystallion “ ”稀罕物“: ”普通“},{ ”名“: ”magicdeer_midnightdeer“, ”稀罕物“: ”特殊“},{ ”名“:” horse_ofthesea”, “稀罕物”: “罕见”},{ “名”: “horse_wingedsea”, “罕见”: “superRare”}]}, “姓名”: “rubyCount_60”}]}, “各具特色”:{ “配方”:{ “配方”:[{ “名称”: “qdke”} ,{ “名称”: “sb1p”},{ “名称”: “cb8v”}]}}, “listEndDate”: “2015年7月13日”, “currencyItem”:{ “名称”: “healingpotionbottle”}, “feed”:{“throttleTime”:“21600”},“name”:“submerging_island”}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtoqa66028 2015-06-24 19:16
    已采纳

    To get you going my 2 cents. First off, Welcome, please read How to ask a good question

    First you need to decode the json string in to an array. with that array you can get the values.

    <?php
    
    $json = '{"prereqs":{"prereq":{"type":"prereq_check","value":"submerging_island_feature_enabled"}},
    "divisions":{"division":[{"items":{"item":[{"name":"rhino_shell","rarity":"common"},
    {"name":"walrus_wavy","rarity":"special"},{"name":"hippo_fancyshell","rarity":"rare"},
    {"name":"rhino_jellyfish","rarity":"superRare"}]},"name":"rubyCount_30"},
    {"items":{"item":[{"name":"walrus_clam","rarity":"common"},{"name":"hippo_nautical","rarity":"special"},
    {"name":"giraffe_coral","rarity":"rare"},{"name":"elephant_starburst","rarity":"superRare"}]},"name":"rubyCount_40"},
    {"items":{"item":[{"name":"giraffe_waverider","rarity":"common"},{"name":"pony_sea","rarity":"special"},
    {"name":"magicdeer_seadeer","rarity":"rare"},
    {"name":"pony_seaprincesscorn","rarity":"superRare"}]},"name":"rubyCount_50"},
    {"items":{"item":[{"name":"bigcat_crystallion","rarity":"common"},{"name":"magicdeer_midnightdeer","rarity":"special"},
    {"name":"horse_ofthesea","rarity":"rare"},
    {"name":"horse_wingedsea","rarity":"superRare"}]},"name":"rubyCount_60"}]},"crafting":{"recipes":{"recipe":[{"name":"qdke"},
    {"name":"sb1p"},{"name":"cb8v"}]}},"listEndDate":"07/13/2015","currencyItem":{"name":"healingpotionbottle"},"feed":{"throttleTime":"21600"},"name":"submerging_island"}';
    
    //decode the json
    $decoded = json_decode($json, true);
    
    
    // uncomment if you want it to be easier to read
    // echo "<pre>";
    // print_r($decoded);
    // echo "</pre>";
    
    //if you want the singe value, i.e. name of the first item.
    echo "If you want a sinle value:<br>";
    echo $decoded['divisions']['division'][0]['items']['item'][0]['name'] . "<br>";
    
    //to get all names from one item  you need to use a foreach() loop. 
    echo "<br>if you want all names from one item:<br>";
    foreach($decoded['divisions']['division'][0]['items']['item'] AS $value){
        echo $value['name'] . "<br>";
    }
    
    //to get all names we need to use 2 foreach loops because this is nested in multiple arrays
    echo "<br>if you want all names from all items:<br>";
    foreach($decoded['divisions']['division'] AS $value){
        foreach($value['items']['item'] AS $value){
            echo $value['name'] . "<br>";
        }
    }
    
    ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题