Oc-json file Parsing-json web site Learning

Source: Internet
Author: User

1 //JSON2 //a subset of JavaScript syntax3 //Key:value similar to dictionary objects4 //JSON is composed of arrays and objects5 6 //The outermost structure of the 1.json file is a dictionary or an array, most of which are dictionaries7 //2.json data can be a basic data type, a string object, an Array object ([] contains), a Dictionary object, a logical object ({} contains), NULL,8 9 intMainintargcConst Char*argv[]) {Ten @autoreleasepool { One  A #if0 -         //1. First read the JSON file to the bit NSData type data -         //NSData *data = [NSData datawithcontentsoffile:@ ""]; theNSString *datastring = [NSString stringwithcontentsoffile:@"/users/qianfeng/desktop/day21-oc11_ Time Class/day21_oc11_json file parsing/network JSON parsing. txt"encoding:nsutf8stringencoding Error:nil]; -NSData *data =[datastring datausingencoding:nsutf8stringencoding]; -          -         //2. Parsing JSON data +Nsdictionary *dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil]; -          +NSLog (@"%@", dict); A #endif at     } -      - @autoreleasepool { -         //parsing JSON URLs -         //Convert a String object to a URL -NSString *aurl =@"Http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103&format=json&appid=379020&bk_ key=%e9%93%b6%e9%ad%82&bk_length=600"; inNsurl *url =[[Nsurl alloc] initwithstring:aurl]; -NSString *urlstring =[NSString stringwithcontentsofurl:url encoding:nsutf8stringencoding Error:nil]; to          +NSData *data =[URLString datausingencoding:nsutf8stringencoding]; -Nsdictionary *dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil]; the          *NSLog (@"%@", dict); $     }Panax Notoginseng     return 0; -}

Oc-json file Parsing-json web site Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.