-1

I string contain \ character. All character inserted properly but this '\'.

My json created is like this : [{"desc":"\"}] PHP Code :

$mparajson = '{"arrayofvalues":false,"recordcount":1,"rows":[{"desc":"\\"}]}';

$jsall  = array();
$jsone  = array();
$jsall_all = json_decode($mparajson, true);
$jsall =  $jsall_all["rows"];

$x = 0;
$jsone=$jsall[$x];

$jsone is null

Silambarasan R.D
  • 1,176
  • 13
  • 20
Honey Last
  • 137
  • 1
  • 6

2 Answers2

0

Make it like below (Four backslashes).

$mparajson = '{"arrayofvalues":false,"recordcount":1,"rows":[{"desc":"\\\\"}]}';

You can test this as follows,

$sample_array = ['arrayofvalues' => false, 'recordcount' => 1, 'rows' => ['desc' => '\\']];

echo '<pre>';
print_r(json_decode(json_encode($sample_array), true));
exit;

Ref: How to deal with backslashes in json strings php

Silambarasan R.D
  • 1,176
  • 13
  • 20
0

Your JSON string is not formatted right. Try this:

$mparajson = '{"arrayofvalues":false,"recordcount": 1, "rows":{"desc":"something with slashes \\\\"}}';

When escaping in JSON you have to use a backslash. Since you had two back slashes, you need two out in front.

mrwpress
  • 302
  • 1
  • 8