Amarok 最近的时间轴更新
Amarok

Amarok

V2EX 第 131448 号会员,加入于 2015-08-07 10:03:06 +08:00
Amarok 最近回复了
2016-12-21 11:49:41 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
@xuhaoyangx 啊啊啊啊啊我瞎了.....这么低级的问题,捂脸......
2016-12-21 11:47:08 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
@sjn9588 对...是 null
2016-12-21 11:40:00 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
@xuhaoyangx 太着急了刚刚,已经贴上了.....谢谢~
2016-12-21 11:39:06 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
@hinkal 贴上了....谢谢~
2016-12-21 11:38:04 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
jsonText :
{
"Posting": [
{
"UserName": "小袁",
"FocusName": "衰神",
"status": "未审核",
"sportsName": "网球",
"ptype": "原创",
"ID": "11",
"sportstypeName": "竞技球类",
"baseTitle": "小米手环 2 开箱及与小米手环 1 对比",
"fixedTitle": "小米哈哈 666",
"seen": "900",
"collection": "170",
"sendTime": "08 27 2016 11:11AM",
"pid": "20160827111111",
"titleimg": "http://imageqiniu.xxxxxbbs.com/FrtK2K9JqwoE6xhYWRPFv9tIZym4?watermark/1/image/aHR0cDovLzd4c2N3NS5jb20wLnowLmdsYi5xaW5pdWNkbi5jb20vd2F0ZXJtYXJrLnBuZw==/gravity/South/dy/5",
"Contents": "aaa"
}
]
}
2016-12-21 11:36:38 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
还没发完就被老板叫过去了....回来补上代码....

PostingExample.class
public class PostingExample {
private List<PostingDetail> Postings;

public List<PostingDetail> getPostings() {
return Postings;
}

public void setPostings(List<PostingDetail> postings) {
Postings = postings;
}

}


PostingDetail .class
public class PostingDetail {
private String FocusName;
private String status;
private String sportsName;
private String ptype;
private String UserName;
private String ID;
private String postType;
private String baseTitle;
private String fixedTitle;
private String sportstypeName;
private String collection;
private String sendTime;
private String pid;
private String titleimg;
private String contents;

public String getID() {
return ID;
}

public void setID(String ID) {
this.ID = ID;
}

public String getBaseTitle() {
return baseTitle;
}

public void setBaseTitle(String baseTitle) {
this.baseTitle = baseTitle;
}

public String getFixedTitle() {
return fixedTitle;
}

public void setFixedTitle(String fixedTitle) {
this.fixedTitle = fixedTitle;
}

public String getCollection() {
return collection;
}

public void setCollection(String collection) {
this.collection = collection;
}

public String getSendTime() {
return sendTime;
}

public void setSendTime(String sendTime) {
this.sendTime = sendTime;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getPid() {
return pid;
}

public void setPid(String pid) {
this.pid = pid;
}

public String getTitleimg() {
return titleimg;
}

public void setTitleimg(String titleimg) {
this.titleimg = titleimg;
}

public String getFocusName() {
return FocusName;
}

public void setFocusName(String focusName) {
FocusName = focusName;
}

public String getSportstypeName() {
return sportstypeName;
}

public void setSportstypeName(String sportstypeName) {
this.sportstypeName = sportstypeName;
}

public String getSportsName() {
return sportsName;
}

public void setSportsName(String sportsName) {
this.sportsName = sportsName;
}

public String getPtype() {
return ptype;
}

public void setPtype(String ptype) {
this.ptype = ptype;
}

public String getUserName() {
return UserName;
}
2016-12-21 11:31:56 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
getPostings().size()就报空指针...T.T
2016-12-21 11:27:07 +08:00
回复了 Amarok 创建的主题 Android Gson 报空指针...死活搞不明白怎么回事,求指点~~
String jsonText = jsonStringTool.Optimization(s);
Log.e(TAG, jsonText);


Gson detailGson = new Gson();

PostingExample postingExample = detailGson.fromJson(jsonText,PostingExample.class);
String id = postingExample.getPostings().get(1).getID();
String pID = postingExample.getPostings().get(1).getPid();

String Contents = postingExample.getPostings().get(1).getContents();
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", id);
map.put("pID", pID);


map.put("Contents", Contents);

log 出来的 json 字符串没问题...到操作 get ( 1 )的时候就报空指针...
关于   ·   帮助文档   ·   API   ·   FAQ   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   2174 人在线   最高记录 5497   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 16:04 · PVG 00:04 · LAX 08:04 · JFK 11:04
♥ Do have faith in what you're doing.