我正在使用占星術API發送一個json字符串作爲對查詢的響應。但我一直試圖將其轉換爲json並從響應字符串中檢索不同的項目。下面是響應的例子:獲取json字符串元素
{"ashtakoota":{"status":true,"received_points":26},"manglik":{"status":true,"male_percentage":13.25,"female_percentage":13.75},"rajju_dosha":{"status":false},"vedha_dosha":{"status":false},"conclusion":{"match_report":"Marriage between the prospective bride and groom is highly recommended. The couple would have a long-lasting relationship, which would be filled with happiness and affluence."}}
我使用PHP腳本,所以我嘗試了下面的代碼:
$json = json_decode($res1, true); TRY 1 --> echo array_values($json[1]); TRY 2 --> echo $json.ashtakoota.status; TRY 3 --> echo $res1.ashtakoota.status;
但產量始終是空白。我懷疑$ json是空的還是json響應不是完美的json。
嘗試4:$ json ['ashtakoota'] ['status'] – YvesLeBorg
非常感謝朋友。有效。 – Vivek