如何将JSON中的JSON转换为数组?

时间:2018-01-06 11:36:18

标签: arrays json

{
    "highestEducationQualification": "graduate",
    "company": "ABB LIMITED",
    "sbiDesignation": "ASSISTANT DIRECTOR",
    "availedSbiCard": "yes",
    "sbiAppliedPastSixMonths": "no",
    "availedCC": "yes",
    "sbiAssociateBanks": "no",
    "userAccountNumber": "9876545678",
    "residenceAddress": "{"doorNo":"12","addressLine1":"dfffsfsf","addressLine2":"wrwrw","pincode":"600017","city":"Chennai","state":"Tamil Nadu"}",
    "officeAddress": "{"doorNo":"2323","addressLine1":"sdsdsdsd","addressLine2":"sdfds","pincode":"600017","city":"Chennai","state":"Tamil Nadu"}"
}

2 个答案:

答案 0 :(得分:0)

它不完全是json格式。你应该在使用之前转换它(使用你的语言中的任何str_replace()函数):

  1. 将所有"{"转换为{"
  2. 将任何"}"转换为"}
  3. 你在数组中有错误。

    错误

    "residenceAddress": "{"doorNo":" .....
    

    更正

    "residenceAddress": {"doorNo":" .....
    

    现在您可以使用json_decode()

答案 1 :(得分:0)

试试这个

<?php
 $test = '{"highestEducationQualification": "graduate","company": "ABB LIMITED","sbiDesignation": "ASSISTANT DIRECTOR","availedSbiCard":"yes","sbiAppliedPastSixMonths":"no","availedCC":"yes","sbiAssociateBanks":"no","userAccountNumber":"9876545678","residenceAddress":{"doorNo":"12","addressLine1":"dfffsfsf","addressLine2":"wrwrw","pincode":"600017","city":"Chennai","state":"Tamil Nadu"},"officeAddress":{"doorNo":"2323","addressLine1":"sdsdsdsd","addressLine2":"sdfds","pincode":"600017","city":"Chennai","state":"Tamil Nadu"}}';  

print_r(json_decode($test, true));
?>

工作小提琴

http://phpfiddle.org/main/code/bge6-qcn4