【发布时间】:2010-09-12 21:21:34
【问题描述】:
我正在将我的 Android 应用程序连接到 wcf 服务,在我的 Log.i 中,我可以看到它返回的数据正确,我唯一想将其作为 JSON 处理,但我的服务以 XML 形式发送——(我认为):应用中的代码如下所示:
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);
我的示例方法看起来像这样,我不知道如何从 WCF 网络服务返回正确的 JSON 数据:
/// <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;
}
这是我得到的错误:
09-12 17:11:04.924: WARN/System.err(437): org.json.JSONException: Value
【问题讨论】: