Objective-C JSON文本不以数组或对象和选项开头,以允许未设置片段

时间:2016-04-25 21:00:00

标签: ios json xml

我正在尝试从Web服务获取XML,执行以下操作:

NSString *areaDescriptionWSpaceCharacters = [areaDescription componentsJoinedByString:@","];
    areaDescriptionWSpaceCharacters = [areaDescriptionWSpaceCharacters stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString *requestString = [NSString stringWithFormat:@"%@?areaDescriptionPLXml=%@",kIP,areaDescriptionWSpaceCharacters];
    NSURL *JSONURL = [NSURL URLWithString:requestString];

    NSURLResponse* response = nil;
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:JSONURL];
    NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
    if(data == nil)
        return nil;
    NSError *myError;
    NSDictionary *punchList = [[NSDictionary alloc]initWithDictionary:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&myError]];

但是我收到了这个错误:

[0] (null)  @"NSDebugDescription" : @"JSON text did not start with array or object and option to allow fragments not set." for `myError`

这是我的XML:

<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89>
  <KeyValueOfstringPunchListCellModel84zsBx89>
    <Key>ORC0023</Key>
    <Value>
      <baseOrSchedStartList>
        <string>2015-09-11T08:00:00</string>
        <string>2015-08-10T16:00:00</string>
        <string>2015-08-11T16:00:00</string>
       </baseOrSchedStartList>
    </Value>
  </KeyValueOfstringPunchListCellModel84zsBx89>
</ArrayOfKeyValueOfstringPunchListCellModel84zsBx89>

我做错了什么?

1 个答案:

答案 0 :(得分:3)

您的XML是...... XML。不是JSON。

尝试使用第三方,例如: https://github.com/nicklockwood/XMLDictionary

用于XML解析。