1

Good morning,

I have a very specific example that I am trying to implement. The goal is to get the following JSON end result.

{
    merchantId :"123456",
    tenderType :"Card",
    amount :"0.02",
    account :
    {
        number : "4111",
        expiryMonth : "02",
        expiryyear : "2016",
        cvv : "019",
        avsZip : "30014",
        avsStreet: "2001 Main"
    }
}

I am familiar with json_encode and I have can get this done for the 1st 3 parameters with the following code:

json_encode(
        array(
                "merchantId" => "123456",
                "tenderType" => "Card",
                "amount" => "0.02"
              )
    }

but the 4th parameter (account) is getting me stuck. Can anybody explain to me how to incorporate the 4th parameter that is itself an array.

George

1 Answer 1

1

It should just be a nested associative array:

json_encode(
    array(
        "merchantId" => "123456",
        "tenderType" => "Card",
        "amount" => "0.02",
        "account" => array(
            "number" => "4111",
            "expiryMonth" => "02",
            "expiryyear" => "2016",
            "cvv " => "019",
            "avsZip" => "30014",
            "avsStreet" => "2001 Main" 
        )  
    )
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.