我遇到的问题是我的XML是通过SQL生成的,并且在Objective-C中使用了NSJSONSerialization
我有两个XML
第一个XML:
<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89 xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<KeyValueOfstringPunchListCellModel84zsBx89>
<Key>ORC0023</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/LosaniHomesSchedulingWebAPI.Models">
<d3p1:baseOrSchedStartList>
<string>11-09-2015 8:00:00 AM</string>
<string>10-08-2015 4:00:00 PM</string>
<string>11-08-2015 4:00:00 PM</string>
<string>12-08-2015 4:00:00 PM</string>
<string>13-08-2015 4:00:00 PM</string>
<string>14-08-2015 4:00:00 PM</string>
<string>14-08-2015 4:00:00 PM</string>
<string>25-08-2015 4:00:00 PM</string>
<string>31-07-2015 4:00:00 PM</string>
<string>14-09-2015 8:00:00 AM</string>
<string>14-09-2015 8:00:00 AM</string>
<string>14-10-2015 5:00:00 PM</string>
<string>15-10-2015 8:00:00 AM</string>
<string>16-10-2015 8:00:00 AM</string>
<string>19-10-2015 8:00:00 AM</string>
<string>21-10-2015 8:00:00 AM</string>
<string>23-10-2015 8:00:00 AM</string>
<string>27-10-2015 8:00:00 AM</string>
<string>28-10-2015 8:00:00 AM</string>
<string>29-10-2015 8:00:00 AM</string>
<string>02-11-2015 8:00:00 AM</string>
<string>02-11-2015 8:00:00 AM</string>
<string>04-11-2015 8:00:00 AM</string>
<string>09-11-2015 8:00:00 AM</string>
<string>11-11-2015 8:00:00 AM</string>
<string>12-11-2015 8:00:00 AM</string>
<string>23-11-2015 8:00:00 AM</string>
<string>26-11-2015 8:00:00 AM</string>
<string>27-11-2015 8:00:00 AM</string>
<string>27-11-2015 8:00:00 AM</string>
<string>01-12-2015 8:00:00 AM</string>
<string>02-12-2015 5:00:00 PM</string>
<string>02-12-2015 5:00:00 PM</string>
<string>03-12-2015 8:00:00 AM</string>
<string>03-12-2015 8:00:00 AM</string>
<string>10-12-2015 8:00:00 AM</string>
<string>17-12-2015 8:00:00 AM</string>
<string>15-02-2016 8:00:00 AM</string>
<string>15-02-2016 8:00:00 AM</string>
<string>16-02-2016 8:00:00 AM</string>
<string>23-02-2016 8:00:00 AM</string>
<string>01-03-2016 8:00:00 AM</string>
<string>02-03-2016 8:00:00 AM</string>
<string>03-03-2016 8:00:00 AM</string>
<string>08-03-2016 5:00:00 PM</string>
<string>09-03-2016 8:00:00 AM</string>
<string>21-03-2016 8:00:00 AM</string>
<string>24-03-2016 8:00:00 AM</string>
<string>31-03-2016 8:00:00 AM</string>
<string>07-04-2016 8:00:00 AM</string>
<string>14-04-2016 8:00:00 AM</string>
<string>19-04-2016 8:00:00 AM</string>
<string>20-05-2016 8:00:00 AM</string>
<string>25-05-2016 8:00:00 AM</string>
<string>31-05-2016 8:00:00 AM</string>
<string>01-06-2016 8:00:00 AM</string>
<string>09-06-2016 8:00:00 AM</string>
<string>10-06-2016 8:00:00 AM</string>
<string>13-06-2016 8:00:00 AM</string>
<string>21-06-2016 8:00:00 AM</string>
</d3p1:baseOrSchedStartList>
<d3p1:sortOrder>0</d3p1:sortOrder>
</Value>
</KeyValueOfstringPunchListCellModel84zsBx89>
这是我使用NSJSONSerialization时返回的内容:
{"ORC0023":{"baseOrSchedStartList":["11-09-2015 8:00:00 AM","10-08-2015 4:00:00 PM","11-08-2015 4:00:00 PM","12-08-2015 4:00:00 PM","13-08-2015 4:00:00 PM","14-08-2015 4:00:00 PM","14-08-2015 4:00:00 PM","25-08-2015 4:00:00 PM","31-07-2015 4:00:00 PM","14-09-2015 8:00:00 AM","14-09-2015 8:00:00 AM","14-10-2015 5:00:00 PM","15-10-2015 8:00:00 AM","16-10-2015 8:00:00 AM","19-10-2015 8:00:00 AM","21-10-2015 8:00:00 AM","23-10-2015 8:00:00 AM","27-10-2015 8:00:00 AM","28-10-2015 8:00:00 AM","29-10-2015 8:00:00 AM","02-11-2015 8:00:00 AM","02-11-2015 8:00:00 AM","04-11-2015 8:00:00 AM","09-11-2015 8:00:00 AM","11-11-2015 8:00:00 AM","12-11-2015 8:00:00 AM","23-11-2015 8:00:00 AM","26-11-2015 8:00:00 AM","27-11-2015 8:00:00 AM","27-11-2015 8:00:00 AM","01-12-2015 8:00:00 AM","02-12-2015 5:00:00 PM","02-12-2015 5:00:00 PM","03-12-2015 8:00:00 AM","03-12-2015 8:00:00 AM","10-12-2015 8:00:00 AM","17-12-2015 8:00:00 AM","15-02-2016 8:00:00 AM","15-02-2016 8:00:00 AM","16-02-2016 8:00:00 AM","23-02-2016 8:00:00 AM","01-03-2016 8:00:00 AM","02-03-2016 8:00:00 AM","03-03-2016 8:00:00 AM","08-03-2016 5:00:00 PM","09-03-2016 8:00:00 AM","21-03-2016 8:00:00 AM","24-03-2016 8:00:00 AM","31-03-2016 8:00:00 AM","07-04-2016 8:00:00 AM","14-04-2016 8:00:00 AM","19-04-2016 8:00:00 AM","20-05-2016 8:00:00 AM","25-05-2016 8:00:00 AM","31-05-2016 8:00:00 AM","01-06-2016 8:00:00 AM","09-06-2016 8:00:00 AM","10-06-2016 8:00:00 AM","13-06-2016 8:00:00 AM","21-06-2016 8:00:00 AM"],"sortOrder":0},"ORC0045":{"baseOrSchedStartList":["24-01-2016 8:00:00 AM","28-01-2016 8:00:00 AM","29-01-2016 8:00:00 AM","30-01-2016 8:00:00 AM","31-01-2016 8:00:00 AM","31-01-2016 4:00:00 PM","24-04-2015 8:00:00 AM","07-05-2015 8:00:00 AM","11-05-2015 5:00:00 PM","01-06-2015 8:00:00 AM","12-05-2015 8:00:00 AM","23-06-2015 5:00:00 PM","23-06-2015 5:00:00 PM","24-06-2015 8:00:00 AM","25-06-2015 8:00:00 AM","27-06-2015 8:00:00 AM","25-06-2015 8:00:00 AM","30-06-2015 8:00:00 AM","03-07-2015 8:00:00 AM","17-06-2015 4:00:00 PM","08-07-2015 8:00:00 AM","21-06-2015 4:00:00 PM","11-07-2015 8:00:00 AM","21-07-2015 8:00:00 AM","23-07-2015 8:00:00 AM","24-07-2015 8:00:00 AM","03-08-2015 9:00:00 AM","08-08-2015 8:00:00 AM","07-08-2015 8:00:00 AM","01-09-2015 8:00:00 AM","08-09-2015 8:00:00 AM","12-09-2015 5:00:00 PM","05-08-2015 5:00:00 PM","14-09-2015 9:00:00 AM","14-09-2015 9:00:00 AM","23-09-2015 8:00:00 AM","02-10-2015 8:00:00 AM","06-10-2015 8:00:00 AM","06-10-2015 8:00:00 AM","09-10-2015 8:00:00 AM","16-10-2015 8:00:00 AM","21-10-2015 8:00:00 AM","22-10-2015 8:00:00 AM","23-10-2015 8:00:00 AM","24-10-2015 5:00:00 PM","26-10-2015 9:00:00 AM","29-10-2015 8:00:00 AM","02-11-2015 9:00:00 AM","04-11-2015 8:00:00 AM","06-11-2015 8:00:00 AM","09-11-2015 9:00:00 AM","12-11-2015 8:00:00 AM","27-05-2016 8:00:00 AM","31-05-2016 8:00:00 AM","04-06-2016 8:00:00 AM","06-06-2016 9:00:00 AM","13-06-2016 9:00:00 AM","14-06-2016 8:00:00 AM","15-06-2016 8:00:00 AM","23-06-2016 8:00:00 AM"],"sortOrder":1}}
这是第二个XML:
<Root>
<KeyValue>
<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>
<string>2015-08-12T16:00:00</string>
<string>2015-08-13T16:00:00</string>
<string>2015-08-14T16:00:00</string>
<string>2015-08-14T16:00:00</string>
<string>2015-08-25T16:00:00</string>
<string>2015-07-31T16:00:00</string>
<string>2015-09-14T08:00:00</string>
<string>2015-09-14T08:00:00</string>
<string>2015-10-14T17:00:00</string>
<string>2015-10-15T08:00:00</string>
<string>2015-10-16T08:00:00</string>
<string>2015-10-19T08:00:00</string>
<string>2015-10-21T08:00:00</string>
<string>2015-10-23T08:00:00</string>
<string>2015-10-27T08:00:00</string>
<string>2015-10-28T08:00:00</string>
<string>2015-10-29T08:00:00</string>
<string>2015-11-02T08:00:00</string>
<string>2015-11-02T08:00:00</string>
<string>2015-11-04T08:00:00</string>
<string>2015-11-09T08:00:00</string>
<string>2015-11-11T08:00:00</string>
<string>2015-11-12T08:00:00</string>
<string>2015-11-23T08:00:00</string>
<string>2015-11-26T08:00:00</string>
<string>2015-11-27T08:00:00</string>
<string>2015-11-27T08:00:00</string>
<string>2015-12-01T08:00:00</string>
<string>2015-12-02T17:00:00</string>
<string>2015-12-02T17:00:00</string>
<string>2015-12-03T08:00:00</string>
<string>2015-12-03T08:00:00</string>
<string>2015-12-10T08:00:00</string>
<string>2015-12-17T08:00:00</string>
<string>2016-02-15T08:00:00</string>
<string>2016-02-15T08:00:00</string>
<string>2016-02-16T08:00:00</string>
<string>2016-02-23T08:00:00</string>
<string>2016-03-01T08:00:00</string>
<string>2016-03-02T08:00:00</string>
<string>2016-03-03T08:00:00</string>
<string>2016-03-08T17:00:00</string>
<string>2016-03-09T08:00:00</string>
<string>2016-03-21T08:00:00</string>
<string>2016-03-24T08:00:00</string>
<string>2016-03-31T08:00:00</string>
<string>2016-04-07T08:00:00</string>
<string>2016-04-14T08:00:00</string>
<string>2016-04-19T08:00:00</string>
<string>2016-05-20T08:00:00</string>
<string>2016-05-25T08:00:00</string>
<string>2016-05-31T08:00:00</string>
<string>2016-06-01T08:00:00</string>
<string>2016-06-09T08:00:00</string>
<string>2016-06-10T08:00:00</string>
<string>2016-06-13T08:00:00</string>
<string>2016-06-21T08:00:00</string>
</baseOrSchedStartList>
</Value>
</KeyValue>
</Root>
你可以看到它们非常相似(除了第二个有Root,第一个没有)
这是我使用NSJSONSerialization时返回的内容:
{"Root":{"KeyValue":[{"Key":"ORC0023","Value":{"baseOrSchedStartList":{"string":["2015-09-11T08:00:00","2015-08-10T16:00:00","2015-08-11T16:00:00","2015-08-12T16:00:00","2015-08-13T16:00:00","2015-08-14T16:00:00","2015-08-14T16:00:00","2015-08-25T16:00:00","2015-07-31T16:00:00","2015-09-14T08:00:00","2015-09-14T08:00:00","2015-10-14T17:00:00","2015-10-15T08:00:00","2015-10-16T08:00:00","2015-10-19T08:00:00","2015-10-21T08:00:00","2015-10-23T08:00:00","2015-10-27T08:00:00","2015-10-28T08:00:00","2015-10-29T08:00:00","2015-11-02T08:00:00","2015-11-02T08:00:00","2015-11-04T08:00:00","2015-11-09T08:00:00","2015-11-11T08:00:00","2015-11-12T08:00:00","2015-11-23T08:00:00","2015-11-26T08:00:00","2015-11-27T08:00:00","2015-11-27T08:00:00","2015-12-01T08:00:00","2015-12-02T17:00:00","2015-12-02T17:00:00","2015-12-03T08:00:00","2015-12-03T08:00:00","2015-12-10T08:00:00","2015-12-17T08:00:00","2016-02-15T08:00:00","2016-02-15T08:00:00","2016-02-16T08:00:00","2016-02-23T08:00:00","2016-03-01T08:00:00","2016-03-02T08:00:00","2016-03-03T08:00:00","2016-03-08T17:00:00","2016-03-09T08:00:00","2016-03-21T08:00:00","2016-03-24T08:00:00","2016-03-31T08:00:00","2016-04-07T08:00:00","2016-04-14T08:00:00","2016-04-19T08:00:00","2016-05-20T08:00:00","2016-05-25T08:00:00","2016-05-31T08:00:00","2016-06-01T08:00:00","2016-06-09T08:00:00","2016-06-10T08:00:00","2016-06-13T08:00:00","2016-06-21T08:00:00"]}}},{"Key":"ORC0045","Value":{"baseOrSchedStartList":{"string":["2016-01-24T08:00:00","2016-01-28T08:00:00","2016-01-29T08:00:00","2016-01-30T08:00:00","2016-01-31T08:00:00","2016-01-31T16:00:00","2015-04-24T08:00:00","2015-05-07T08:00:00","2015-05-11T17:00:00","2015-06-01T08:00:00","2015-05-12T08:00:00","2015-06-23T17:00:00","2015-06-23T17:00:00","2015-06-24T08:00:00","2015-06-25T08:00:00","2015-06-27T08:00:00","2015-06-25T08:00:00","2015-06-30T08:00:00","2015-07-03T08:00:00","2015-06-17T16:00:00","2015-07-08T08:00:00","2015-06-21T16:00:00","2015-07-11T08:00:00","2015-07-21T08:00:00","2015-07-23T08:00:00","2015-07-24T08:00:00","2015-08-03T09:00:00","2015-08-08T08:00:00","2015-08-07T08:00:00","2015-09-01T08:00:00","2015-09-08T08:00:00","2015-09-12T17:00:00","2015-08-05T17:00:00","2015-09-14T09:00:00","2015-09-14T09:00:00","2015-09-23T08:00:00","2015-10-02T08:00:00","2015-10-06T08:00:00","2015-10-06T08:00:00","2015-10-09T08:00:00","2015-10-16T08:00:00","2015-10-21T08:00:00","2015-10-22T08:00:00","2015-10-23T08:00:00","2015-10-24T17:00:00","2015-10-26T09:00:00","2015-10-29T08:00:00","2015-11-02T09:00:00","2015-11-04T08:00:00","2015-11-06T08:00:00","2015-11-09T09:00:00","2015-11-12T08:00:00","2016-05-27T08:00:00","2016-05-31T08:00:00","2016-06-04T08:00:00","2016-06-06T09:00:00","2016-06-13T09:00:00","2016-06-14T08:00:00","2016-06-15T08:00:00","2016-06-23T08:00:00"]}}}]}}
你可以看到这看起来与第一个JSON不同。为什么这样做以及解决这个问题的最佳方法是什么?这是我的存储过程。基本上我正在尝试的是采用第一个XML并在SQL中重做它(我做了,并且是第二个XML),但它没有正确地序列化它。我究竟做错了什么?
如果需要,我可以提供生成XML的SQL。
以下是我为获取JSON数据而进行的调用:
NSDictionary *punchList = [[NSDictionary alloc]initWithDictionary:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&myError]];