0

I am writing an app in which i am allowing user to enter their product details into a framework [i have made on PHP] and then by using that framework i am encoding data into json and that encoded data i am retrieving in my Android App using web services.

But now issue is i am not able to encode web image url therefore i am not getting correct image path in json:-

Like:

I have given this link to encode into JSON:

  "imageurl" => "http://www.libpng.org/pub/png/img_png/pnglogo-blk-sml1.png"

but whenever i see encoded web image url in JSON getting something like this:

    "imagepath":"http:\/\/www.libpng.org\/pub\/png\/img_png\/pnglogo-blk-sml1.png"

why i am getting wrong image url....

I don't know how can i resolve this issue..please someone help me....

albums.php:

      <?php
/*
*Simple JSON generation from static array
*Author: JSR
*/

include_once './data.php';
$albums = array();

// looping through each album
foreach ($album_tracks as $album) {
$tmp = array();
$tmp["id"] = $album["id"];
$tmp["name"] = $album["album"];
$tmp["description"] = $album["detail"];
$tmp["imagepath"] = $album["imageurl"];
$tmp["songs_count"] = count($album["songs"]);

// push album
array_push($albums, $tmp);
}

//printing json
echo json_encode($albums);
?>

data.php:

        <?php
/*
*Simple JSON generation from static array
*Author: JSR
*/
$album_tracks = array(
1 => array(
"id" => 1,
"album" => "Appetizers",
"detail" => "All appetizers served with mint and tamarind chutneys.",
"imageurl" => "http://www.libpng.org/pub/png/img_png/pnglogo-blk-sml1.png"
)
));
?>
ASMUIRTI
  • 1,332
  • 10
  • 20
  • This is a [perfectly valid JSON result for the input provided](http://jsfiddle.net/dgnBL/2/); what is the issue you're trying to resolve? – TML Feb 12 '13 at 05:05
  • @TML my encoded json url: http://erachnida.net/android/albums.php in my android app i am not getting images in a listview...so i guess i am doing mistake in encoding web image url..please let me know, am i getting correct path in my encoded JSON...? – ASMUIRTI Feb 12 '13 at 05:12
  • 1
    There's absolutely nothing wrong with that path in the JSON. Note the [railroad diagram](http://json.org/string.gif) for string parsing from json.org - you can do the solidus ('/') with or without a preceding backslash. No conforming JSON implementation should choke on it either way. – TML Feb 12 '13 at 05:13
  • Maybe this post gives you the answer http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped – kaddo Feb 12 '13 at 05:14

1 Answers1

0

For me it works

<script>
    var str="http:\/\/www.libpng.org\/pub\/png\/img_png\/pnglogo-blk-sml1.png";
    document.write("<img src='" + str + "'/>");
</script>

Whenever you send image path or url in json, it escapes all the slashes, quotes, etc. So you can use some regex like s/\////gis to get rid of these escapes characters and get the original url or location.