I need your help, i don't get it on my own. May the gap with me.
I got two classes: The first one (Application) has a method (toJson) to return its private variables as json-string.
The second (Problem) contains the first class and is able to return its own content and the content of its child as json.
Now, if i call the toJson-method of the superior second class, this method calls the toJson-method of its child.
Both toJson-methods are using json_encode. The logical consequence is, that the final-result contains escape characters.
{"Application":"{\"Abbreviation\":\"GB\",\"Identifier\":1,\"Name\":\"Great Bounce"\"}"}
The toJson-Method of Application is similar to this:
public function toJson()
{
return json_encode(array(
"Abbreviation" => $this->_Abbreviation,
"Identifier" => $this->_Identifier->getId(),
"Name" => $this->_Name
));
}
The toJson-Method of Problem:
public function toJson()
{
return json_encode(array(
"Application" => $this->_Application->toJson();
));
}
The escape chars are causing issues with JavaScript. Does someone comes a solution or different implementation into mind?
JSON.parsecan handle these perfectly fine, and directly injecting the JSON into code should work just as fine. You just have to decode twice.