2013-05-10 10 views
13

का उपयोग कर सर्वर से पंजीकरण डेटा भेजने के लिए नेस्टेड JSON भेजें, मैं JSON उपयोग कर रहा हूँ निम्नलिखित रूप में है:AFNetworking

यहाँ कैसे भेज रहा हूँ है।

NSURL * url = [[NSURL alloc] initWithString:registerUrlString]; 
      AFHTTPClient * httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; 
      httpClient.parameterEncoding = AFJSONParameterEncoding; 
      [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; 
      NSDictionary * params = @{@"regData": @{ 
               @"City": self.cityField.text, 
               @"Country": self.countryField.text, 
               @"Email_Id": self.emailField.text, 
               @"MobileNumber": self.numberField.text, 
               @"UserName": self.userName.text, 
               } 
             }; 

      NSMutableURLRequest * request = [httpClient requestWithMethod:@"POST" path:registerUrlString parameters:params]; 
      AFHTTPRequestOperation * operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
       NSLog(@"Success: %@", JSON); 

      } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 
      NSLog(@"Error: %@", [error debugDescription]); 
      }]; 

      [operation start]; 

लेकिन दुर्भाग्य से मैं इस त्रुटि हो रही है:

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x94b3c30 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

+1

आपकी विधि सामान्य नहीं है। उचित विधि की जांच करें [यहां] (http://stackoverflow.com/questions/14958883/ios-serialize-deserialize-complex-json-generically-from-nsobject-class)। कम त्रुटि-प्रवण और रखरखाव –

उत्तर

32

आपका अनुरोध प्राप्त करने के लिए ठीक है। त्रुटि Error Domain=NSCocoaErrorDomain Code=3840 वापस किया जा रहा है क्योंकि आपका सर्वर अमान्य JSON ऑब्जेक्ट का जवाब दे रहा है। NSLogoperation.responseString यह देखने के लिए कि क्या वापस भेजा जा रहा है।

+2

धन्यवाद, मैट! मैंने पहले ही इस मुद्दे को ठीक कर दिया था। जैसा आपने बताया था समस्या थी। मैं सर्वर से स्ट्रिंग प्राप्त कर रहा था बल्कि एक जेसन। – Homam

+1

@mattt, मैंने उपclassed, 'AFHTTPSessionManager' मुझे 'operation.responseString' कहां मिल सकता है? – Hemang

+0

@Hemang आपको "त्रुटि डोमेन = NSCocoaErrorDomain कोड = 3840" से संबंधित कोई समाधान मिला? – Akhtar

2

इस प्रयास करें वास्तविक त्रुटि

NSLog(@"Error: %@", [error debugDescription]); 
NSLog(@"Error: %@", [error localizedDescription]); 
+4

मुझे यह त्रुटि मिल रही है: त्रुटि डोमेन = NSCocoaErrorDomain कोड = 3840 "ऑपरेशन पूरा नहीं हो सका। (कोको त्रुटि 3840.)" (JSON टेक्स्ट सरणी या ऑब्जेक्ट और अनुमति देने के विकल्प से शुरू नहीं हुआ टुकड़े सेट नहीं हैं।) UserInfo = 0x94b3c30 {NSDebugDescription = जेएसओएन पाठ सरणी या ऑब्जेक्ट और विकल्प के साथ शुरू नहीं हुआ है ताकि टुकड़े सेट न किए जा सकें।} – Homam