I have a multi-platform Cordova app backed by a .net web service which returns JSON data for syncing. This works fine.
I am now trying to add native calls into the Android version of the app which are hooked into BroadcastReceiver so that I can provide rich notifications when the app isn't running.
The scheduling and execution of these events are running fine; but I am having real problems in processing the result of the web service call.
The web service call (VB.net) is:
<OperationContract()>
<WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json)>
Public Function SyncNotifications_Native(ByVal dateAfter As String, ByVal which As Integer, ByVal userID As Int32) As String
Dim rowsList As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
:::
:::
While dr.Read()
row = New Dictionary(Of String, Object)
row.Add("allow_reply", dr("allow_reply"))
row.Add("content", dr("content"))
row.Add("date_added", dr("date_added")
row.Add("date_deleted", dr("date_deleted")
row.Add("date_read", dr("date_read")
row.Add("deleted", dr("deleted"))
row.Add("last_update", Now().ToString("yyyy-MM-dd HH:mm:ss"))
row.Add("notification_id", dr("notification_id"))
row.Add("subject_line", dr("subject_line"))
row.Add("user_id", dr("user_id"))
rowsList.Add(row)
End While
Return New JavaScriptSerializer().Serialize(details)
End Function
This should return an array of zero or more entries. I'm using an AsyncTask to get the data. This is the data I get back from the call:
{"d":"
[{\"allow_reply\":1,\"content\":\"test content\",
\"date_added\":\"2016-02-04 23:37:50\",\"date_deleted\":\"\",
\"date_read\":\"\",\"deleted\":0,\"last_update\":\"2016-02-04 23:38:43\",
\"notification_id\":27,\"subject_line\":\"test\",\"user_id\":1}]
"}
I've looked at various resources and have tried all types of solutions. This is what I'm currently doing:
Convert the return string to a JSON Object:
JSONObject json2 = new JSONObject(s);
Try to get the array out of the object:
JSONArray results = json2.getJSONArray("d");
This way gives me an error of:
java.lang.String cannot be converted to JSONArray
I've seen a suggestion in another post that I'm actually returning a SOAP response from my web service; I'm not sure, I haven't seen any other example JSON responses which start with
{"d":
How can I properly get the returned array into a JSONArray so that I can pass it off to another function?
Thanks