아래 형식으로 JSON 데이터를 가지고 있습니다. 오류가 발생하기 때문에 어떻게 값을 게시 할 수 있습니까? Domain : NSCocoaErrorDomain "Json Text가 배열 또는 개체로 시작되지 않았으며 조각이 설정되지 않은 옵션을 허용합니다 !!! 도와주세요 !!!
[
{ "No:"1" , "firstname":dhruv ....},
{ "No:"2", "firstname" : something i want to post...} ]
암호:
Nsstring* URL string = [NStringwithformat:@Myurl?fname=%(value from editext ]
NSArray *arrData = @[@{
@"No": @"1",
@"firstname": @"dhruv"},
@{
@"No": @"2",
@"firstname": @"something i want to post"
}];
NSData *data = [NSJSONSerialization dataWithJSONObject:arrData options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"your url here"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *dataTask = [session uploadTaskWithRequest: request
fromData:data completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//Kindly use below either one according to your response
//If the response is in Dictionary format
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", jsonDict);
//If the response is in Array format
NSArray *jsonArr = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", jsonArr);
}];
[dataTask resume];
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다