2016-12-17 11 views
5
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-Shopify-Access-Token: $token")); 
$translation_json = curl_exec($ch); 
$translation_decoded= json_decode($translation_json, true); 

परिणाम है:php json_decode सरणी से मानों का उपयोग कैसे करें?

Array 
(
    [asset] => Array 
     (
      [key] => locales/en.default.json 
      [public_url] => 
      [value] => { 
    "general": { 
    "accessibility": { 
     "skip_to_content": "Skip to content", 
     "close_modal": "Close (esc)" 
    }, 
    "meta": { 
     "tags": "Tagged \"{{ tags }}\"", 
     "page": "Page {{ page }}" 
    }, 
    "404": { 
     "title": "404 Page Not Found", 
     "subtext": "The page you requested does not exist.", 
     "link": "Continue shopping" 
    }, 
    "pagination": { 
     "previous": "Previous", 
     "next": "Next", 
     "current_page": "Page {{ current }} of {{ total }}" 
    }, 
    "password_page": { 
     "opening_soon": "Opening Soon", 
     "login_form_heading": "Enter store using password", 
     "login_form_password_label": "Password", 
     "login_form_password_placeholder": "Your password", 
     "login_form_submit": "Enter", 
     "signup_form_email_label": "Email", 
     "signup_form_success": "We will send you an email right before we open!", 
     "admin_link_html": "Are you the store owner? Log in here<\/a>", 
     "password_link": "Enter using password", 
     "powered_by_shopify_html": "This shop will be powered by {{ shopify }}" 
    }, 
    "social": { 
     "share_on_facebook": "Share", 
     "share_on_twitter": "Tweet", 
     "share_on_pinterest": "Pin it", 
     "alt_text": { 
     "share_on_facebook": "Share on Facebook", 
     "share_on_twitter": "Tweet on Twitter", 
     "share_on_pinterest": "Pin on Pinterest" 
     } 
    }, 
    "search": { 
     "no_results_html": "Your search for \"{{ terms }}\" did not yield any results.", 
     "results_with_count": { 
     "one": "{{ count }} result for \"{{ terms }}\"", 
     "other": "{{ count }} results for \"{{ terms }}\"" 
     }, 
     "title": "Search our site", 
     "placeholder": "Search", 
     "submit": "Submit", 
     "close": "Close search" 
    }, 
    "newsletter_form": { 
     "newsletter_email": "Join our mailing list", 
     "email_placeholder": "Email address", 
     "confirmation": "Thanks for subscribing", 
     "submit": "Subscribe" 
    }, 
    "filters": { 
     "show_more": "Show More", 
     "show_less": "Show Less" 
    } 
    }, 

मैं एक json प्रतिक्रिया से इस सरणी डीकोड, लेकिन इस लूप करने के लिए समस्या का सामना? मैं accessibility, 404, password_page, social और अधिक से मूल्यों का उपयोग करना चाहता हूं। मैं इससे मूल्य कैसे प्राप्त करूं?

+1

आप शायद सिर्फ पर एक बार और डिकोड करने के लिए है '$ translation_decoded [ 'संपत्ति'] [ ' मूल्य ']' उस मान को किसी अन्य सरणी में रूपांतरित करने के लिए। – Rasclatt

+0

ठीक है, लेकिन इसके लिए अधिक नेस्टेड मान हैं। तो मुझे यह हर घोंसला मूल्य के लिए करना है? –

+0

वैसे यह मान जेसन एन्कोडेड है, इसलिए यदि अन्य मूल्य हैं जिन्हें लगातार जेसन के रूप में कोड किया जाता है, तो हाँ – Rasclatt

उत्तर

2

क्योंकि है कि अभी भी json प्रारूप में आप फिर से मानों को डीकोड करने की जरूरत है सरणी में इसे बनाने के लिए

$decode = json_decode($translation_decoded['asset']['value']); 
1
$accessibility=$translation_decoded['asset']['value']['general']['accessibility'] ; 
$social=$translation_decoded['asset']['value']['social'] ; 
$password_page=$translation_decoded['asset']['value']['password_page'] ; 
$Page404=$translation_decoded['asset']['value']['404'] ; 

आप इस तरह से उपयोग कर सकते हैं। कृपया इसे आजमाएं।

0

अपने json_decode funciton के लिए तीसरे $depth विकल्प जोड़ने, यह कैसे manual उल्लेख उपयोग करने के लिए और इस post

$translation_decoded= json_decode($translation_json, true, $depth); 
संबंधित मुद्दे