How to parse JSON in iOS App

前端 未结 6 1983
栀梦
栀梦 2020-11-29 09:55

Im getting a response from twitter in the form of a string,

What I need is to send the parts where is a comment to an array,

here an example of the string

6条回答
  •  再見小時候
    2020-11-29 10:32

    -(IBAction)btn_parse_webserivce_click:(id)sender
    {
    // Take Webservice URL in string.
    NSString *Webservice_url = self.txt_webservice_url.text;
    NSLog(@"URL %@",Webservice_url);
    // Create NSURL from string.
    NSURL *Final_Url = [NSURL URLWithString:Webservice_url];
    // Get NSData from Final_Url
    NSData* data = [NSData dataWithContentsOfURL:
    Final_Url];
    //parse out the json data
    NSError* error;
    // Use NSJSONSerialization class method. which converts NSData to Foundation object.
    
    NSDictionary* json = [NSJSONSerialization
    JSONObjectWithData:data
    options:kNilOptions
    error:&error];
    // Create Array
    NSArray* Response_array = [json objectForKey:@"loans"];
    NSLog(@"Array: %@", Response_array);
    // Set Response_array  to textview.
    self.txt_webservice_response.text = [NSString stringWithFormat:@"%@"
    ,Response_array];
    }
    

提交回复
热议问题