如何从PHP中的json中提取字符串? [等候接听]

loading...


0

更新我之前的(现已删除的问题) . 我的(WordPress)插件接受REST API上的json . 一切顺利 . 但我无法将字符串提取到PHP(v 7.2)变量中 .

代码

public function mbo( WP_REST_Request $request ) {
    $body = $request->get_body();
    write_log("mbo: body=" .  $body ); // OK
    $json = json_decode( $body, true );
    $intake_info = $json['body']['acf']['intake_info'];
    $fname="undef"; // see output below
    foreach ($intake_info as $key => $value){
        if ($key == "intake_family_name"){
            write_log("key=".$key."<<value=".$value);
            $fname = $value;
            write_log("intake2family: fname=".$fname);// WHY THIS IS EMPTY?
        }
    }
    return 0;

}

输出(为清晰起见略微修剪)

[10-Dec-2018 10:15:40 UTC] mbo: body={"body":{"acf":{
"intake":{"intake_date":"12/10/2018","intake_team":"xsxsxs","intake_q1":"","intake_q2":"","intake_q3":"","intake_q3_other":"","intake_q4":""},
"intake_info":{"intake_date":"10/12/2018","intake_status":"yyyy","intake_yahav_member":"xsxsxs","intake_qdate":"10/12/2018","intake_mgr_decision":"ppppp","intake_mgr_decision_explain":"","intake_comments":"","intake_family_decision":"kkkkkk","intake_family_name":"aaaaaaaaa","intake_family_woman_name":"bbbbbbbbbbbbbb","intake_family_man_name":"ccccccccccc","referral_code":"6841","intake_code":"6861"}}}}

[10-Dec-2018 10:15:40 UTC] key=intake_family_name<<value=aaaaaaaaa

[10-Dec-2018 10:15:40 UTC] intake2family: fname=

loading...

0回答

No Data

评论

暂时没有评论!