Hi,
I have written a C# web service as below to generate a JSON string or so I assumed.
List<Dictionary<String, Object>> lstdict = new List<Dictionary<String, Object>>();
...
...
... Logic for connecting db and getting records in msqldat (data reader) goes here.
while (msqldat.Read())
{
var detls = new Dictionary<string, object>();
for (int i = 0; i < msqldat.FieldCount; i++)
{
detls.Add(msqldat.GetName(i), msqldat.IsDBNull(i) ? null :
msqldat.GetValue(i));
lstdict.Add(detls);
}
}
JavaScriptSerializer jss = new JavaScriptSerializer();
String mret = jss.Serialize(lstdict);
The above webservice method is called in my java code and the below string is received.
{"GetDataResult":"[
{\"uname\":\"hkIUZIikXVTC5aNaSva8IQ==\",\"passwd\":\"hkIUZIikXVTC5aNaSva8IQ==\",\"validupto\":\"\\\/Date(1545330600000)\\\/\",\"dept\":\"juubHSHgLr\/3JWnrZCh5LeeW5Q7lioWOZ1\/Tg+YRy\/o=\",\"rid\":1},{\"uname\":\"hkIUZIikXVTC5aNaSva8IQ==\",\"passwd\":\"hkIUZIikXVTC5aNaSva8IQ==\",\"validupto\":\"\\\/Date(1545330600000)\\\/\",\"dept\":\"juubHSHgLr\/3JWnrZCh5LeeW5Q7lioWOZ1\/Tg+YRy\/o=\",\"rid\":2}]"}
I am trying to get the values in android application by using this Java code :
JSONObject uiobj = new JSONObject(mret);
JSONArray arrUserinfo = uiobj.getJSONArray("GetDataResult");
At the second line the code fails with this error :
..... at GetDataResult of type java.lang.String cannot be converted to JSONArray
Please suggest how do I go about it ? Thanks in advance. Am i wrong from the c# side or java side.
What I have tried:
The similar code I have found everywhere and not able to get it to work. So I thought my JSON string requires a different method of approach and hence posted here. Im new to JSON, please bear ignorance.