2

how can convert URL encoded JSON sent from my android application into PHP array.Current format i am getting looks like below format.

[{\\\"product_id\\\":\\\"33\\\",\\\"amount\\\":\\\"1\\\"},{\\\"product_id\\\":\\\"34\\\",\\\"amount\\\":\\\"3\\\"},{\\\"product_id\\\":\\\"10\\\",\\\"amount\\\":\\\"1\\\"}]

How can i convert those data into below format


product_id    amount
   33         1 
   34         3 
   10         1 

Because i want to insert those data into MySQL database.Can anyone please help me regarding this problem.

2

3 Answers 3

2

Use json_decode :

echo json_decode($jsonarr);
Sign up to request clarification or add additional context in comments.

1 Comment

@Damith, this means that the json passed to it cannot be decoded or if the encoded data is deeper than the recursion limit as explained in the php manual.
2

this can be done by json_decode

$json = '{"foo": 12345}';

$obj = json_decode($json);
print $obj->{'foo'}; // 12345

Good read

--- common mistakes using json_decode()

Comments

1

json_decode(jsonencoded string, TRUE) is correct way to encode json string.

But your json string encoded too deeper and recursive. your json encode string should as below

[{"product_id":9,"amount":500},{"product_id":9,"amount":500},{"product_id":9,"amount":500}]

Other wise, you will get NULL value

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.