Error Listing Object Data in PHP

0

As you list these response data, especially IMG, the data below BELOW:

  $data = file_get_contents("php://input");
  $objData = json_decode($data);

  $categoria = $objData->categoria->name_categoria;
  $titulo = $objData->titulo;
  $texto = $objData->texto;
  $data = $objData->data;
  $autor = $objData->autor;
  $status = $objData->status;
  $img = $objData->img->name;
{
   [functions]: ,
   __proto__: { },
   autor: "Luquinhas Brito",
   categoria: {
      [functions]: ,
      __proto__: { },
      date_categoria: "12/04/2017",
      id_categoria: 1,
      name_categoria: "Geral",
      status_categoria: "1",
      type_categoria: "news"
   },
   data: "26/04/2017",
   img: {
      [functions]: ,
      __proto__: { },
      lastModifiedDate: [date] Mon Jul 18 2016 20:53:17 GMT-0300 (Hora oficial do Brasil),
      name: "Capturar.JPG",
      size: 78623,
      type: "image/jpeg",
      webkitRelativePath: ""
   },
   status: "1",
   texto: "..",
   titulo: "Titulo Test"
}

The following is the error:

( ! ) Notice: Undefined property: stdClass::$name in C:\wamp64\www\Projeto_Sara\pages\admin\server-processing\cadastrarNews.php on line 12 Call Stack #TimeMemoryFunctionLocation 10.0005396592{main}( )...\index.php:0 20.0013432280router->routing( )...\index.php:69 30.03731824648require( 'C:\wamp64\www\Projeto_Sara\pages\admin\server-processing\cadastrarNews.php' )...\router.class.php:100  
    
asked by anonymous 26.04.2017 / 22:02

1 answer

0

You do not have a valid json code, tested with jslint . You can test with the echo json_last_error_msg () function, it should return syntax error. Try this:

$data = file_get_contents("php://input");
$objData = json_decode($data);

echo json_last_error_msg ();

$categoria = $objData->categoria->name_categoria;

Your json should look something like this:

{
    "img": {
        "lastModifiedDate": "[date] Mon Jul 18 2016 20:53:17 GMT-0300 (Hora oficial do Brasil)",
        "name": "Capturar.JPG",
        "size": 78623,
        "type": "image/jpeg",
        "webkitRelativePath": ""
    }
}

You should fix the json encoding before sending the content to your php.

    
27.04.2017 / 03:22