issue when outputting an http:// address in a sub-array with json and php -
I'm trying to get an output like this
{"status" : "Ok", "0": {"id": "11", "title": "digg", "url": "http://www.digg.com"}}
but instead I am receiving it
{"status": "ok", "0": {"id": "11", "title": " Digg "," url ":" http: \ / \ / www.digg.com "}}
This is the PHP code being used to generate jsson
$ links = array ('id' = & gt; '11 ',' title '= & gt;' digg ',' url '= & gt; "http://www.digg.com "); $ Msg = array ('position' = & gt; 'right', $ link); Echo json_encode ($ msg);
Any idea what's going on?
UPDATE I should pay attention to the actual URL, "should be in the" before "/" in the output, or is there a way to stop it?
Both of these are valid, JSON, so it should not make any difference. JSON string:
"http://www.digg.com"
and
"http: / \ / Www.digg.com "
decode for both:
" http://www.digg.com "
This is a different issue, but I like:
$ links = array (array ('id' => '11 ',' title '= & Gt; 'digg', 'url' = & gt; "http://www.digg.com")); $ Msg = array ('position' = & gt; 'right', 'link' = & gt; $ link); Echo json_encode ($ msg); {"Status": "OK", "link": [{"id": "11", "title": "digg", "url": "http: \ / \ / www.digg.com"} ]}
It makes sense to me more than the "0" key, and if you add more sites it is well spread:
< Code> $ links = array (array ('id' => '11 ',' title '=>' digg ',' url '= & gt; "http://www.digg.com") , Array ('id' => gt; '12', 'title' = & gt; 'reddit', 'url' = & gt; "http://www.reddit.com")); $ Msg = array ('position' = & gt; 'right', 'link' = & gt; $ link); Echo json_encode ($ msg); {"Status": "OK", "link": [{"id": "11", "title": "digg", "url": "http: \ / \ / www.digg.com"} , {"Id": "12", "title": "reddit", "url": "http: \ / \ / www.reddit.com"}}}
Comments
Post a Comment