Twitter typeahead显示'&amp'而不是'&'

I'm trying to display search-results with the sign & in them. But when I render from php to json & converts to &amp.

Is there anyway I can prevent that, or before I print the names in the search-bar convert it back to &?

Thanks in advance!

EDIT: HTML JS:

                {
              name: 'industries',
              prefetch: 'industries_json.json',
              header: '<h1><strong>Industries</strong></h1>',
              template: '<p>{{value}}</p>',
              engine: Hogan
            },

industries_json.json (Created with json_encode)

[{"id":42535,"value":"AUTOMOBILES &AMP; COMPONENTS","type":"industries"}]

php-script which ouputs json:

    public function renderJSON($data){
    header('Content-type: application/json');
    echo json_encode($data);
}

The issue you're facing is HTML encoding. What you want is to decode the text before sending it to the client. It is important that you only decode the text properties of the JSON object (rather than the entire JSON object itself).

Here is a reference on HTML decoding in PHP: http://php.net/manual/en/function.html-entity-decode.php

Use html_entity_decode function like...

Code Before:

public function renderJSON($data){
    header('Content-type: application/json');
    echo json_encode($data);
}

output: Gives html code in string like ex: appthemes &amp; Vantage search Suggest

Code After:

public function renderJSON($data){
    header('Content-type: application/json');
    $data = json_encode($data);
    echo html_entity_decode( $data );
}

output: Gives html code in string like ex: appthemes & Vantage search Suggest

I would do it in javascript. Once you have got the JSON, just use replace function of javascript on the JSON like this:

first convert it to string by this:

var jsonString=JSON.stringify(jsonData);

then replace &amp like this.

jsonString=jsonString("&amp","&");

then again, convert it to JSON obj;

jsonObj=JSON.parse(jsonString);

now, your JSON, will have & instead of &amp.

What's next ?

Do whatever you need to do with the jsonObj