Obtain PHP object data but it has a json array at the end

0

Good evening, I have a problem trying to get the answer from the webservices of afip. I send a request to the ws of afip and it returns me the following.

I want to get the error but if you see it, the WS response is a stdclass and below a whole JSON array.

How can I access the values of the stdclass array?

If I make a parseJSON (object); He does not do anything, like he dies there. And if I try to access the fix, I'm undefined. And I can not access Code or Msg.

    
asked by Fede M. 08.04.2017 в 04:36
source

2 answers

1

What you want to do is not easy, since you have a var_dump , not a real serialization of an object (PHP offers several methods to serialize and de-serialize as json , serialize or wddx , but it is not any of them). You will have to make your own function to take out the data.

To separate the dump from the json, make a split by \n . The last line is the json, all the previous ones the dump of the object.

    
answered by 08.04.2017 в 09:41
0

If the query is launched using Ajax I think you should add an error control (in jQuery ".ajaxError ()") where you would collect and you could analyze the string returned by the webservices. I do not know why you get the error but working with JSON data is very easy to damage your exquisite syntax due mainly to transcoding between servers when sending / receiving data (UTF-8 to ASCII and so on) and in file read / write operations for the same reason, maybe even a single non-visible mark (UTF without BOM) in the file from where you obtained the JSON string, and even depending on the OS where the server works: Windows, Linux, Unix, ... by control characters (return, new line, ...)

JSON is a good way to convey information but is quite strict with its syntax: simple commas, omit the initial 0 in decimals, undefined instead of null , ... any control character. Maybe you should look for the JSON string sent and make sure it does not include any special or not allowed characters. You may find some JSON validation software or even online tools such as: link

    
answered by 16.09.2017 в 17:39