发布请求当我转换数据获得额外的括号

时间:2017-07-25 09:31:05

标签: ios xcode post

我正在发送一个帖子请求但是当我从jsonDict中提取值时,我得到一个额外的括号,因此设置为我的标签的值没有被设置,因为这个额外的括号“(”

下面是我的帖子方法

NSString *post = [NSString stringWithFormat:@"store_id=%@",self.str];
NSLog(@"DATA sending details :%@",self.str);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//Next up, we read the postData's length, so we can pass it along in the request.
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
// Now that we have what we'd like to post, we can create an NSMutableURLRequest, and include our postData
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://riterp.com/all_product.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSLog(@"the data Details is %@", post);
//   And finally, we can send our request, and read the reply by creating a new NSURLSession:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession* sharedSessionMainQueue = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:[NSOperationQueue mainQueue]];

NSLog(@"Request = %@", request);
[[sharedSessionMainQueue dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json st
    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; // you need to convert to dictionary object
    //NSDictionary *temp=jsonDict;
    NSLog(@"Req cust  3:%@",requestReply);
    NSLog(@"requestReply cust liqour categoryn=  3: %@", jsonDict);
    NSLog(@"liq new val %@",[[[jsonDict valueForKey:@"items"] objectAtIndex:0]mutableCopy]);
    _itemss=[[[jsonDict valueForKey:@"items"]objectAtIndex:0]mutableCopy];
    NSLog(@"------------------%@",_itemss);

    _nametb=[_itemss valueForKey:@"liquor_name"];
    NSLog(@"name tb -------%@",_nametb);
    _regtb=[_itemss valueForKey:@"base_price_old"];
    NSLog(@"regular tb -------%@",_regtb);

    _buytb=[_itemss valueForKey:@"bidacceptance_price"];
    NSLog(@"buy tb -------%@",_buytb);

    _lowesttb=[_itemss valueForKey:@"min_price"];
    NSLog(@"lowest tb -------%@",_lowesttb);

}] resume];

以及我从服务器获取的数据

2017-07-25 14:42:07.966 Barebones[4288:163703] requestReply cust liqour    categoryn=  3: (
        {
    category = "Wines & Sparkling Cocktails";
    items =         (
                    {
            "_id" = 591d382b19c5c7401a771a49;
            "base_price_old" = "199.00";
            "bidacceptance_price" = "1047.51";
            "bidacceptance_price_old" = "339.00";
            "buy_now_price" = "1078.41";
            "buy_now_price_old" = "349.00";
            "category_name" = "Wines & Sparkling Cocktails";
            "high_demand" = 0;
            id = 4130;
            image = "sangria.png";
            "liquor_name" = "Sangria Pitcher - Red";
            "liquor_stock" = 0;
            "low_demand" = 0;
            "max_price" = "399.00";
            "max_price_old" = "399.00";
            "max_stock_limit" = 0;
            "min_price" = "634.8099999999999";
            "min_price_old" = "209.00";
        },
                    {
            "_id" = 5925650d21c4038f27df47c4;
            "base_price_old" = "189.00";
            "bidacceptance_price" = "834.21";
            "bidacceptance_price_old" = "279.00";
            "buy_now_price" = "894.01";
            "buy_now_price_old" = "299.00";
            "category_name" = "Wines & Sparkling Cocktails";
            "high_demand" = 0;
            id = 4153;
            image = "Bigbanyanshiraz.png";
            "liquor_name" = "Big Banyan Shiraz - Glass";
            "liquor_stock" = 0;
            "low_demand" = 0;
            "max_price" = "399.00";
            "max_price_old" = "399.00";
            "max_stock_limit" = 0;
            "min_price" = "584.01";
            "min_price_old" = "199.00";
        },
                    {
            "_id" = 591d382c03bd5c49049ba157;
            "base_price_old" = "189.00";
            "bidacceptance_price" = "834.21";
            "bidacceptance_price_old" = "279.00";
            "buy_now_price" = "894.01";
            "buy_now_price_old" = "299.00";
            "category_name" = "Wines & Sparkling Cocktails";
            "high_demand" = 0;
            id = 4151;
            image = "cabernetsauvigonBigbanyan.png";
            "liquor_name" = "Big Banyan Cabernet Sauvignon - Bottle";
            "liquor_stock" = 0;
            "low_demand" = 0;
            "max_price" = "399.00";
            "max_price_old" = "399.00";
            "max_stock_limit" = 0;
            "min_price" = "584.01";
            "min_price_old" = "199.00";
        },

  );
},
    {
    category = "American Whsikey";
    items =         (
                    {
            "_id" = 591d382b19c5c7401a771a49;
            "base_price_old" = "199.00";
            "bidacceptance_price" = "1047.51";
            "bidacceptance_price_old" = "339.00";
            "buy_now_price" = "1078.41";
            "buy_now_price_old" = "349.00";
            "category_name" = "Wines & Sparkling Cocktails";
            "high_demand" = 0;
            id = 4130;
            image = "sangria.png";
            "liquor_name" = "Sangria Pitcher - Red";
            "liquor_stock" = 0;
            "low_demand" = 0;
            "max_price" = "399.00";
            "max_price_old" = "399.00";
            "max_stock_limit" = 0;
            "min_price" = "634.8099999999999";
            "min_price_old" = "209.00";
        },
                    {
            "_id" = 5925650d21c4038f27df47c4;
            "base_price_old" = "189.00";
            "bidacceptance_price" = "834.21";
            "bidacceptance_price_old" = "279.00";
            "buy_now_price" = "894.01";
            "buy_now_price_old" = "299.00";
            "category_name" = "Wines & Sparkling Cocktails";
            "high_demand" = 0;
            id = 4153;
            image = "Bigbanyanshiraz.png";
            "liquor_name" = "Big Banyan Shiraz - Glass";
            "liquor_stock" = 0;
            "low_demand" = 0;
            "max_price" = "399.00";
            "max_price_old" = "399.00";
            "max_stock_limit" = 0;
            "min_price" = "584.01";
            "min_price_old" = "199.00";
        },

目标: - 我想在我的表视图中打印酒名最小价格最高价格的值,因为括号“(”我没有得到数据和当前代码I. h

1 个答案:

答案 0 :(得分:0)

该括号“(”表示items是一个jsonObjects数组,而不是一个jsonObject