[英]storing array content into dictionary with keys properly
我有這個:
NSURL *url = [NSURL URLWithString:@"http://www.ios.com/ios/responseScript.php"];
NSError *error = nil;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:&error];
NSMutableArray *someArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSLog(@"Array Retrieved: %@", someArray);
它顯然從站點獲取json數據。 這樣創建PHP數組:
$simpleProduct = array("John"=>"Employee","Jane"=>"Student","Jhonson"=>"Somejob","Mike"=>"Nothing");
echo json_encode($simpleProduct);
當上面的objective-c代碼的結果被打印時,它顯示為:
2013-02-05 19:17:37.910 testProducts [26786:c07]檢索到的數組:{Jane = Student; 瓊森= Somejob; 約翰=員工; 邁克=沒什么; }
現在,我希望將此數據插入字典(NSMutableDictionary)中,以便例如Jane是鍵,而Student是值。 對於所有其他對,依此類推。
如何才能做到這一點?
我是iOS開發的新手:)
為什么不只是得到這樣的結果
NSDictionary *someDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
它使您的生活更加輕松,並且只需通過如下鍵即可訪問值
NSString *jane= [someDictionary objectForKey:@"Jane"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.