I have been working on creating a phonegap plugin for Android where I am returning a JSONArray
using
callBackContext.sendPluginResult(result);
. Below is the code snippet demonstrating how I am constructing the JSONArray
:
private JSONArray makeJsonObject(String type, String result, float confidence)
{
JSONObject recogResult = new JSONObject();
JSONArray jsonArray = new JSONArray();
try
{
recogResult.put("type", type);
recogResult.put("result", result);
recogResult.put("confidence", confidence);
jsonArray.put(recogResult);
}
catch(JSONException e)
{
Log.d(LOG_TAG, "JSON Error", e);
}
return jsonArray;
}
The above method generates a result in the following format:
[{"type":"interim","result":"da","confidence":0}]
Next, here is how I attempt to read this data via JavaScript:
function startRecognition()
{
SpeechRecPlug.startRecognition(function(msg){
var data = msg;
var json = JSON.parse(data);
var div = document.getElementById("test");
div.innerHTML = div.innerHTML + " "+ json[1].result;
});
}
However, the problem I am facing is that nothing is being displayed in the HTML. I'm not sure if there is an issue with how I am trying to print the data using JavaScript.
Does anyone have any insights or suggestions on this matter?
UPDATE Upon checking the android console, I observed the following message:
01-19 12:54:57.946: I/chromium(30192): [INFO:CONSOLE(310)] "Error in Success callbackId: SpeechRecPlug1992021962 : SyntaxError: Unexpected token o", source: file:///android_asset/www/cordova.js (310)