0

PHP Noob here...

if i have JSON format: {"0":"0x1001C","1":"0"}
but what i really want is is: {"0x1001C","0"}

how do i attain this?

esentially, i have an array which contains keys and values. i'm removing the keys (as this is a requrement) and the final array must be in object format (in other words, JSON has to return something with {} rather than [] )

Any ideas?

Thanks in advance

2
  • 2
    So you have an object ({} rather than []), you want to convert it to an array and then back to an object??? What you want ({"foo","bar"}) is invalid JSON. {} will always show key-value pairs, [] won't, there's no in-between. Commented Oct 17, 2012 at 16:56
  • ok, phew, good to know, i tried everything to put it in this format and i just couldn't figure out a solution on my own. thanks! Commented Oct 17, 2012 at 16:57

1 Answer 1

2
 echo json_encode(array('0x1001c', '0'), JSON_FORCE_OBJECT);
                                         ^^^^^^^^^^^^^^^^^

as per the docs: http://php.net/json_encode

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.