2015-01-06 57 views
-1

-,我試圖創建結構使用AFNetworking 2.0一個JSONObjects的創建JSONArray Objective-C的

[{'category_id': '3'}, {'category_id': '2'}, {'category_id': '1'}] 

-我試圖創建一個使用該結構的NSMutableDictionary & NSMutableArray一樣,我回來是:

<__NSArrayM 0x7c186080>(
{ 
"category_id" = 1; 
}, 
{ 
"category_id" = 2; 
}, 
{ 
"category_id" = 3; 
} 
) 

-我送這通過HTTPPost服務器。

-但在服務器上請求到達爲:

{(null)[][category_id]': ['1', '2', '3']} 

這是不想要的格式,因爲我在點之上顯示1

-任何人都可以請幫助我出去創建一個JSONArrayJSONObjects,我會非常感激。

,我用來創建和發送請求到服務器的代碼是:

-(void) getProductList:(NSString *)strToken andCatId:(NSArray *)arrCategory{ 
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
[manager.requestSerializer setValue:strToken forHTTPHeaderField:@"Authorization"]; 

manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments]; 


NSString *strSuffix = @"unfollow/productList/"; 
NSString *strUrl = [NSString stringWithFormat:@"%@%@",BASE_URL,strSuffix]; 

api_categoryProductList *currentObj = self; 


[manager POST:strUrl parameters:arrCategory success:^(AFHTTPRequestOperation *operation, id responseObject) { 
[currentObj httpOperationDidSuccess:oper 
ation responseObject:responseObject]; 

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
     [currentObj httpOperationDidFail:operation error:error]; 
    }]; 
} 

回答

0

試試這個:

NSMutableArray *array = [[NSMutableArray alloc] init]; 
NSNumber *id = [NSNumber numberWithInt:1]; 

for (int i = 0; i < 5; ++i) { 
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; 
    [dict setObject:id forKey:@"category_id"]; 
    [array addObject:dict]; 
} 

現在它有靜態ID爲1.您可以更改它無論你喜歡什麼樣的價值。