[iOS 多線程 & 網路 - 2.1] - 解析json

來源:互聯網
上載者:User

標籤:

A.iOS中json的基本使用 1.解析json資料 (1)json還原序列化 對象
{}
格式 {key : value, key : value,...} 的索引值對的結構
可以還原序列化為OC中的NSDictionary
數組
[]
格式 ["java","javascript","vb",...]
可以還原序列化為OC中的NSArray

提示
JSON的資料格式與OC中的快速封裝方法非常類似
JSON的資料格式同樣支援嵌套   (2)json工具 從iOS 5開始,使用NSJSONSerialization對JSON解析

其他常見的三種JSON解析第三方庫:
SBJson 因為API簡單易用,可能還會有一些應用中留存
JSONKit JSONKit的開發人員稱:JSONKit的效能優於蘋果
TouchJson   (3)序列化 & 還原序列化 還原序列化
[NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];

序列化
[NSJSONSerialization dataWithJSONObject:array options:0 error:NULL];   sample:
 1     // 同步發送資訊 2     NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 3     4     // 解析資料 5     if (data) { // 得到返回資料 6         // 解除螢幕鎖 7         [MBProgressHUD hideHUD]; 8         9         // 解析json資料10         NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];11        12         // 處理返回的資料13         NSString *result = dict[@"success"];14         if (result) {15             [MBProgressHUD showSuccess:result];16         } else {17             result = dict[@"error"];18             if (result) {19                 [MBProgressHUD showError:result];20             }21         }22     } else {23         [MBProgressHUD showError:@"網路繁忙,請稍後再試~"];24     }

 

    

[iOS 多線程 & 網路 - 2.1] - 解析json

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.