0

I am using the wp_ajax_ and wp_ajax_nopriv_ in localize script I am passing a big multidimensional array( it's big!). It works without any JSON encode, decodes. But I want to encode it is while I make ajax call...so I used json_encode in localizing script (wp_json_encode also gives the same output).. I pass it through ajax data parameter. now when I access that as
json_decode($_POST['largejson'], true)
i get the response but not as an array but a string with lot of backslashes
\":[{\"field_type\":\"shortcode_elementor_pro\",\"_id

what could be possibly going wrong?

update i use this to debug it

if ($data_settings === null){
        switch (json_last_error()) {
          case JSON_ERROR_NONE:
              echo ' - No errors';
          break;
          case JSON_ERROR_DEPTH:
              echo ' - Maximum stack depth exceeded';
          break;
          case JSON_ERROR_STATE_MISMATCH:
              echo ' - Underflow or the modes mismatch';
          break;
          case JSON_ERROR_CTRL_CHAR:
              echo ' - Unexpected control character found';
          break;
          case JSON_ERROR_SYNTAX:
              echo ' - Syntax error, malformed JSON';
          break;
          case JSON_ERROR_UTF8:
              echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
          break;
          default:
              echo ' - Unknown error';
          break;
          }

it showed - Syntax error, malformed JSON'; so json_encode might be the problem maker

1 Answer 1

0

This fixed my issue $set = stripslashes($set);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.