作者: luckiejacky 時間: 2018-2-19 13:00 標題: [Android Json] 想拿 gsx$name...
- {
- "version": "1.0",
- "encoding": "UTF-8",
- "feed": {
- "xmlns": "http://www.w3.org/2005/Atom",
- "xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
- "xmlns$gsx": "http://schemas.google.com/spreadsheets/2006/extended",
- "id": {
- "$t": "xxx"
- },
- "updated": {
- "$t": "2018-02-18T02:47:36.549Z"
- },
- "category": [
- {
- "scheme": "http://schemas.google.com/spreadsheets/2006",
- "term": "http://schemas.google.com/spreadsheets/2006#list"
- }
- ],
- "title": {
- "type": "text",
- "$t": "Sheet1"
- },
- "link": [
- {
- "rel": "alternate",
- "type": "application/atom+xml",
- "href": "xxx"
- },
- {
- "rel": "http://schemas.google.com/g/2005#feed",
- "type": "application/atom+xml",
- "href": "xxxx"
- },
- {
- "rel": "http://schemas.google.com/g/2005#post",
- "type": "application/atom+xml",
- "href": "xxx"
- },
- {
- "rel": "self",
- "type": "application/atom+xml",
- "href": "xxx"
- }
- ],
- "author": [
- {
- "name": {
- "$t": "xx"
- },
- "email": {
- "$t": "xx@gmail.com"
- }
- }
- ],
- "openSearch$totalResults": {
- "$t": "1"
- },
- "openSearch$startIndex": {
- "$t": "1"
- },
- "entry": [
- {
- "id": {
- "$t": "xxx"
- },
- "updated": {
- "$t": "2018-02-18T02:47:36.549Z"
- },
- "category": [
- {
- "scheme": "http://schemas.google.com/spreadsheets/2006",
- "term": "http://schemas.google.com/spreadsheets/2006#list"
- }
- ],
- "title": {
- "type": "text",
- "$t": "kBYuDEwqT69nXfHV7qqZPg==\n"
- },
- "content": {
- "type": "text",
- "$t": ""
- },
- "link": [
- {
- "rel": "self",Q
- "type": "application/atom+xml",
- "href": "xxx"
- }
- ],
- "gsx$name": {
- "$t": "kBYuDEwqT69nXfHV7qqZPg==\n"
- }
- }
- ]
- }
- }
- JSONObject jsonObject = getJSONObjectFromURL(urlString);
- String s = jsonObject.toString();
- serverMessage.setText(s);
-
- //JSONArray params = jsonObject.getJSONArray("entry");
- //JSONObject param1 = params.getJSONObject(0);
-
- //Object param1 = jsonObject.get("feed");
- String s2 = jsonObject.getString("feed.entry");
-
-
- //String s2 = param1.toString();
- googleText.setText(s2);
PLS HELP
THX
作者: KinChungE 時間: 2018-2-19 13:44
JSONObject obj1 = (JSONObject) jsonObject.get("feed");
JSONObject obj2 = (JSONObject) obj1.get("entry");
JSONObject obj3 = (JSONObject) obj2.get("gsx$name");
String s1 = obj3.getString("$t");
咁得唔得?
JSONObject既get一定要一層層咁入去, 唔可以feed.entry咁用
作者: luckiejacky 時間: 2018-2-19 13:47
Thanks Kin Ching
作者: luckiejacky 時間: 2018-2-19 14:00
Sorry, Kin Ching, the second line already throwing... :(
- JSONObject obj1 = (JSONObject) jsonObject.get("feed");
- JSONObject obj2 = (JSONObject) obj1.get("entry");
作者: KinChungE 時間: 2018-2-19 17:06
JSONObject obj1 = (JSONObject) jsonObject.get("feed");
JSONObject obj2 = (JSONObject) obj1.getJSONArray("entry").get(0);
JSONObject obj3 = (JSONObject) obj2.get("gsx$name");
String s1 = obj3.getString("$t");
睇漏左你果個係json array
作者: 專業收買佬 時間: 2018-2-19 17:40
做咩分咁多次打....一路get落去啦...
作者: KinChungE 時間: 2018-2-19 18:19
要做type casting
一路get落去要N層括號
作者: luckiejacky 時間: 2018-2-19 20:33
Thanks Kin Ching, works now....

