android:json异常
我从服务器端得到一些响应,我需要解析这些响应,但不是通过名称,也就是说,响应会不断变化android:json异常,android,json,Android,Json,我从服务器端得到一些响应,我需要解析这些响应,但不是通过名称,也就是说,响应会不断变化 type = "data_updates"; updates = { "offers_all" = { columns = ( "record_id", "di
type = "data_updates";
updates = {
"offers_all" = {
columns = (
"record_id",
"display_name",
"sorting_name",
latitude,
longitude,
"custom_ad_banner_resource_id",
description,
"website_url",
"phone_number",
hours,
advertiser,
"street_address",
"offer_id",
"offer_section",
"start_date",
"end_date",
"custom_leaf_template",
"location_area"
);
data = (
(
"09834-234234",
"The Example Offer",
"example offer, the",
"-122.234234",
"31.2342343",
"",
"An Example of an Offer.",
"http=>//freeruntech.com/",
"1.707.555.1212",
"10am - 5pm",
Yes,
"3145 State Street,\nCalistoga, CA, 94500",
"",
"",
"2011-08-24",
"2011-12-31",
"",
Napa
)}
我使用以下代码获取主要JSONObject
if (show.get("type").equals("data_updates"))
{
JSONObject data_updates = show.getJSONObject("updates");
JSONArray array_containing_values= new JSONArray();
JSONArray data_updates_values=data_updates.names();
System.out.println(data_updates_values);
for(int m=0; m<data_updates_values.length(); m++)
{
JSONObject obj = new JSONObject((String) data_updates_values.get(m));
JSONArray names = new JSONArray();
names= obj.toJSONArray(names);
System.out.println(names);
}
}
如何获取数据和列的值JSonobjects
有人能帮我吗
谢谢你是这样做的吗
HttpEntity entity = response.getEntity();
if (entity != null) {
// Read the content stream
InputStream instream = entity.getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
instream = new GZIPInputStream(instream);
}
// convert content stream to a String
String resultString= convertStreamToString(instream);
Log.v(null, "resultString "+resultString);
instream.close();
// Transform the String into a JSONObject
if(resultString!=null){
jsonObjRecv = new JSONObject(resultString);
}
// Raw DEBUG output of our received JSON object:
Log.i(TAG,"<jsonobject>\n"+jsonObjRecv.toString()+"\n</jsonobject>");
问题在于它不是一个有效的json。在json=中,被替换为:,并且值数组以[开头,以]结尾,没有;在json中。请看以下链接
它看起来不像是有效的JSON。你确定你得到了JSON的响应吗?@Nikita事实上我刚刚在这里写了一部分,实际上响应非常大。也许你可以用它来验证你的响应,只是为了确定。JSON的符号中没有括号“()”,你是如何得到你的响应的?
HttpEntity entity = response.getEntity();
if (entity != null) {
// Read the content stream
InputStream instream = entity.getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
instream = new GZIPInputStream(instream);
}
// convert content stream to a String
String resultString= convertStreamToString(instream);
Log.v(null, "resultString "+resultString);
instream.close();
// Transform the String into a JSONObject
if(resultString!=null){
jsonObjRecv = new JSONObject(resultString);
}
// Raw DEBUG output of our received JSON object:
Log.i(TAG,"<jsonobject>\n"+jsonObjRecv.toString()+"\n</jsonobject>");
JSONObject jsshow = new JSONObject(show)