@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/**
* 完成对json数据的解析
* @author z
*
*/
public class JsonTool {
public JsonTool() {
}
public static Person getPerson(String key , String jsonString){
Person person = new Person();
try {
JSONObject jsonObject = new JSONObject(jsonString);
JSONObject persJsonObject = jsonObject.getJSONObject("list");
person.setTitle(persJsonObject.getString("title"));
person.setSinger(persJsonObject.getString("singer"));
} catch (Exception e) {
}
return person;
}
}
--------------------编程问答--------------------
这是主要的解析代码、
package com.zzqq.listmusic.json;
import org.json.JSONObject;
import com.zzqq.listmusic.domian.Person;
/**
* 完成对json数据的解析
* @author z
*
*/
public class JsonTool {
public JsonTool() {
}
public static Person getPerson(String key , String jsonString){
Person person = new Person();
try {
JSONObject jsonObject = new JSONObject(jsonString);
JSONObject persJsonObject = jsonObject.getJSONObject("list");
person.setTitle(persJsonObject.getString("title"));
person.setSinger(persJsonObject.getString("singer"));
} catch (Exception e) {
}
return person;
}
}
你解析list的方式貌似不太对。。
给你一个我写的例子吧。。
public static List<Affiliate> convert2AdConfig(String serverJsonStr)
throws JSONException {
AdConfig adconfig = new AdConfig();
JSONObject object = new JSONObject(serverJsonStr);
JSONArray listjson = object.getJSONArray("rations");
List<Affiliate> list = new ArrayList<Affiliate>();
listjson.length();
// 鐢熸垚Affiliate瀵硅薄
for (int i = 0; i < listjson.length(); i++) {
JSONObject object2 = listjson.getJSONObject(i);
Affiliate affiliate = new Affiliate();
// {"platformId":82,"key":"debug","key2":"debug","weight":50,"adapterName":""},
affiliate.setAdapterName(object2.getString("adapterName"));
affiliate.setId(object2.getString("platformId"));
affiliate.setKey1(object2.getString("key"));
affiliate.setKey2(object2.getString("key2"));
affiliate.setWeight(object2.getString("weight"));
System.out.println(affiliate.toString());
list.add(affiliate);
}
return list;
}
--------------------编程问答--------------------
这是主要的解析代码、
package com.zzqq.listmusic.json;
import org.json.JSONObject;
import com.zzqq.listmusic.domian.Person;
/**
* 完成对json数据的解析
* @author z
*
*/
public class JsonTool {
public JsonTool() {
}
public static Person getPerson(String key , String jsonString){
Person person = new Person();
try {
JSONObject jsonObject = new JSONObject(jsonString);
JSONObject persJsonObject = jsonObject.getJSONObject("list");
person.setTitle(persJsonObject.getString("title"));
person.setSinger(persJsonObject.getString("singer"));
} catch (Exception e) {
}
return person;
}
}
你解析list的方式貌似不太对。。
给你一个我写的例子吧。。
public static List<Affiliate> convert2AdConfig(String serverJsonStr)
throws JSONException {
AdConfig adconfig = new AdConfig();
JSONObject object = new JSONObject(serverJsonStr);
JSONArray listjson = object.getJSONArray("rations");
List<Affiliate> list = new ArrayList<Affiliate>();
listjson.length();
// 鐢熸垚Affiliate瀵硅薄
for (int i = 0; i < listjson.length(); i++) {
JSONObject object2 = listjson.getJSONObject(i);
Affiliate affiliate = new Affiliate();
// {"platformId":82,"key":"debug","key2":"debug","weight":50,"adapterName":""},
affiliate.setAdapterName(object2.getString("adapterName"));
affiliate.setId(object2.getString("platformId"));
affiliate.setKey1(object2.getString("key"));
affiliate.setKey2(object2.getString("key2"));
affiliate.setWeight(object2.getString("weight"));
System.out.println(affiliate.toString());
list.add(affiliate);
}