iphone利用JSON傳遞資料

2021-05-25 06:09:57 字數 1724 閱讀 8708

**:

son不必多說了,在手機開發中,客戶端和伺服器端開發經常使用的資料互動模式。iphone中利用json傳遞的資料,可以非常容易的展示到各個容器中。下面是乙個最簡單的例子。效果如圖:

上面用到了json傳遞的資料,有關json部分,iphone sdk雖然沒有支援,但是第三方已經寫好了。

json 參考:

下面是具體的**實現:

資料載入:

#import 「mydatasource.h」

#import 「json.h」

@implementation

mydatasource+(

nsdictionary

*)fetchlibraryinformation+(

id)fetchjsonvalueforurl

:(nsurl

*)url

@end

table資料展示:

#import 「jsontabletestviewcontroller.h」

#import 「mydatasource.h」

@implementation

jsontabletestviewcontroller

@synthesize mydata;-

(void

)viewdidload -(

void

)didreceivememorywarning -(

void

)viewdidunload -(

nsinteger

)numberofsectionsintableview

:(uitableview

*)tableview -(

nsinteger

)tableview

:(uitableview

*)tableview numberofrowsinsection

:(nsinteger

)section -(

uitableviewcell

*)tableview

:(uitableview

*)tableview cellforrowatindexpath

:(nsindexpath

*)indexpath

//上面的東西都是重複白給的,平時沒事不用想為什麼,照抄就可以了

cell

.textlabel

.text =[[

mydata valueforkey

:[[mydata allkeys

]objectatindex

:indexpath

.section

]]objectatindex

:indexpath

.row

];//這句看上去複雜,但是其實不過是在特定section裡面找到對應的array,

//然後在array中找到indexpath.row所在的內容

return

cell;}

-(nsstring

*)tableview

:(uitableview

*)tableview titleforheaderinsection

:(nsinteger

)section-(

void

)dealloc

@end

Ajax傳遞json資料

ajax的傳遞json資料的實現 1.ajax基本案例詳解之 ajax的實現 2.ajax基本案例詳解之 get的實現 現在來看一下具體的內容,在index.jsp的裡面寫 ajax success function data complete function error function 然後再...

傳遞json Golang 解析json

業務需求是這樣的,有兩個json資料,第乙個json是表的欄位名稱及型別 第二個json是欄位名稱及其值。現在,前端傳遞欄位名稱,後端需要根據欄位名稱的型別返回對應的值,如 class是float,就需要返回該字段的最大值 最小值 平均值 總數,class是text,則返回該字段的唯一值,即不重複的...

Ajax傳遞json資料

ajax的傳遞json資料的實現 1.ajax基本案例詳解之 ajax的實現 2.ajax基本案例詳解之 get的實現 現在來看一下具體的內容,在index.jsp的裡面寫 ajax success function data complete function error function 然後再...