Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用restkit进行映射;如何使用多重映射和描述符_Ios_Objective C_Mapping_Restkit - Fatal编程技术网

Ios 使用restkit进行映射;如何使用多重映射和描述符

Ios 使用restkit进行映射;如何使用多重映射和描述符,ios,objective-c,mapping,restkit,Ios,Objective C,Mapping,Restkit,stackoverflow中的朋友您好: 我在使用restkit从api映射数据时遇到问题。我真的想知道我的错误在哪里 Json格式: { data: { -current_condition: [1] 0: { cloudcover: "16" humidity: "59" - weatherDesc: [1] 0: { value: "Clear"

stackoverflow中的朋友您好:

我在使用restkit从api映射数据时遇到问题。我真的想知道我的错误在哪里

Json格式:

{
data: {
   -current_condition: [1]
       0:  {
           cloudcover: "16"
           humidity: "59"
          - weatherDesc: [1]
       0:  {
            value: "Clear"
          }

- weather: [5]
0:  {
    tempMinC: "10"
    tempMinF: "50"
    weatherCode: "119"
  -  weatherDesc: [1]
0:  {
     value: "Cloudy"
     }
    .......
}
下面是我的代码如何进行映射(我尝试在当前条件和天气下映射“云量、湿度”和“天气描述”)

以下是我得到的:

2014-07-16 14:21:36.076 myRestSample[3783:60b] I restkit:RKLog.m:33 RestKit logging initialized...
2014-07-16 14:21:36.154 myRestSample[3783:60b] I 
restkit.network:RKObjectRequestOperation.m:150 GET  
'http://www.raywenderlich.com/demos/weather_sample/weather.php?format=json'
2014-07-16 14:21:36.289 myRestSample[3783:3a0f] I 
restkit.network:RKObjectRequestOperation.m:220 GET  
'http://www.raywenderlich.com/demos/weather_sample/weather.php?format=json' (200 OK / 6
 objects) [request=0.1323s mapping=0.0024s total=0.1525s]
 2014-07-16 14:21:36.289 myRestSample[3783:60b] -[Weather humidity]: unrecognized 
 selector sent to instance 0x8f8eb30
我试图将描述符的键路径更改为“nil”,如下所示

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:currentMapping 
method:RKRequestMethodGET 
pathPattern:@"/demos/weather_sample/weather.php" keyPath:nil 
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
Weather和CurrentCondition是NSObject,CurrentCondition中有四个属性(云量、湿度、NSArray*weaterDesc、Weather*restkitweather)。Weather.h中只有两个属性(NSArray*myweatherDesc、*weatherDesc)

看起来我已经有6个物体了,但为什么我得到了“未恢复的天气湿度”。 有人能帮忙吗

“[天气湿度]未恢复”

这意味着您有一个
Weather
实例,但将其视为当前条件实例


根据我对你的另一个问题的回答,你不应该使用
\u myArr=mappingResult.array因为您无法确定数组包含的内容。相反,您应该使用
字典
并根据关键路径提取符合您需要的正确类型的对象。

类的定义是什么
restkitCurrentCondition
(请注意,类名应以大写字母开头)嘿,朋友!很高兴再次见到您。它是一个NSObject,其中有4个属性(NSNumber*云层、NSNumber*湿度、NSArray*天气描述、restKitWeather*restKitWeather)@Wain我已经在overflow中搜索了关于restkit的问题。你是唯一给出答案的人………你能帮我更多吗?我已经更新了我的问题。你太棒了。你的答案是正确的。问题来自_myArr,我已经解决了。
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:currentMapping 
method:RKRequestMethodGET 
pathPattern:@"/demos/weather_sample/weather.php" keyPath:nil 
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];