I am having issues with JSON parsing. Here is my controller method:
@RemoteAction
global static String GetDetails(string sName)
{
//do soamething with sName later
List<String> sectorList = new List<String>();
sectorList.add('Healthcare');
sectorList.add('Healthcare');
sectorList.add('Healthcare');
return JSON.serialize(sectorList);
}
& here is my JavaScript:
<script type="text/javascript">
function getRemoteDeals(sectorName) {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MyController.GetDetails}',
sectorName,
function(result, event){
if (event.status) {
//do something it is a success
alert(result);
var obj = JSON.parse(result);
alert(obj);
} else if (event.type === 'exception') {
document.getElementById("responseErrors").innerHTML =
event.message + "<br/>\n<pre>" + event.where + "</pre>";
} else {
document.getElementById("responseErrors").innerHTML = event.message;
}
},
{escape: true}
);
}
</script>
Firebug error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
alert(result) throws this --> ["Healthcare","Healthcare","Healthcare"]
Also alert image attached:
result
and add that to your question.