2015-05-28 124 views
0

我是目標新手。 我不明白爲什麼我的函數不起作用,它使函數返回時出現錯誤SIGBART。爲什麼返回功能發出SIGBART信號?

+ (NSArray*) jsonToArray:(NSString*)jsonString 
{ 
    id mappedObj = nil; 
    RKObjectMappingProvider* mapProv = [[RKObjectMappingProvider alloc] init]; 

    RKObjectMapping* answerMapping = [SMAnswersWrapper entityMappingForSerializer]; 
    answerMapping.objectClass = [NSMutableDictionary class]; 

    [mapProv setSerializationMapping:answerMapping forClass:[SMAnswersWrapper class]]; 
    RKObjectMapping *proofsEntityMapping = [SMEntityArrayWrapper entityMappingWithContentMapping:answerMapping]; 

    [mapProv setMapping:proofsEntityMapping forKeyPath:@""]; 

    if (jsonString) 
    { 
     id obj = [jsonString objectFromJSONString]; 
     if (obj) 
     { 
      RKObjectMapper* mapper = [[RKObjectMapper alloc] initWithObject:obj mappingProvider:mapProv]; 

      RKObjectMappingResult* res = [mapper performMapping]; 
      mappedObj = [res asCollection]; 

      [mapper release]; 
     } 
    } 
    [mapProv release]; 
    return [[[mappedObj content] retain] autorelease]; 
} 

錯誤位置是在這一行:

return [[[mappedObj content] retain] autorelease];

謝謝。

編輯

我發現我的錯誤,我不能在[[[mappedObj content] retain] autorelease];訪問的內容,我不得不投mappedObj。

+0

檢查主文件並檢查'UIApplicationMain'是否正常。否則在代碼上放置斷點並檢查錯誤位置。 – Esha

+0

也在'[mapProv setMapping:proofsEntityMapping forKeyPath:@「」]; '你需要提供一個合適的鍵路徑「Key」值。 – Esha

+2

我也真的建議你移動到'ARC' – rckoenes

回答

0

我發現我的錯誤,我不能在[[[mappedObj content] retain] autorelease];訪問的內容,我不得不投mappedObj。

0

嘗試以下操作:

+ (NSArray*) jsonToArray:(NSString*)jsonString 
{ 
    id mappedObj = nil; 
    RKObjectMappingProvider* mapProv = [[RKObjectMappingProvider alloc] init]; 

    RKObjectMapping* answerMapping = [SMAnswersWrapper entityMappingForSerializer]; 
    answerMapping.objectClass = [NSMutableDictionary class]; 

    [mapProv setSerializationMapping:answerMapping forClass:[SMAnswersWrapper class]]; 
    RKObjectMapping *proofsEntityMapping = [SMEntityArrayWrapper entityMappingWithContentMapping:answerMapping]; 

    [mapProv setMapping:proofsEntityMapping forKeyPath:@""]; 

    if (jsonString) 
    { 
     id obj = [jsonString objectFromJSONString]; 
     if (obj) 
     { 
      RKObjectMapper* mapper = [[RKObjectMapper alloc] initWithObject:obj mappingProvider:mapProv]; 

      RKObjectMappingResult* res = [mapper performMapping]; 
      mappedObj = [res asCollection]; 

      [mapper release]; 
     } 
    } 
    [mapProv release]; 
    if (mappedObj) 
    { 
     return [[[mappedObj content] retain] autorelease]; 
    } 
    return [NSArray array]; 

} 

在你的代碼,如果jsonStringobj將是零,mappedObj不會被初始化。這種情況在訪問[mappedObj content]時可能會導致崩潰。

試試這個,這將幫助你.....

+0

謝謝,我已經找到了錯誤,我不能訪問的內容沒有施放我的目的。 – MohamedAli