Iam connecting my Android app to a wcf service, and in my Log.i I can see that it return data correct, The only thing I want to handle it as JSON but my service sends as XML-(I think): this is how the code in the app looks like:
if (entity != null)
{
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null){
sb.append(line + "n");
}
String result = sb.toString();
Log.i(TAG,result);
instream.close();
JSONObject json=new JSONObject(result);
JSONArray nameArray=json.names();
JSONArray valArray=json.toJSONArray(nameArray);
and my example method looks like this, I don't know how to return correct JSON data from the WCF webserivce:
/// <returns>An enumeration of the (id, item) pairs. Returns null if no items are present</returns>
protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()
{
// TODO: Change the sample implementation here
if (items.Count == 0)
{
items.Add("A", new SampleItem() { Value = "A" });
items.Add("B", new SampleItem() { Value = "B" });
items.Add("C", new SampleItem() { Value = "C" });
}
return this.items;
}
This is the error I get: 09-12 17:11:04.924: WARN/System.err(437): org.json.JSONException: Value <ItemInfoList of type java.lang.String cannot be converted to JSONObject