ios - 如何在 iOS 中解析 nsmutabledictionary 时间?
<p><p>我已经使用以下代码解析了 Json</p>
<pre><code>- (void) getWorkingCalendar:(NSData *)dataForParse{
NSMutableArray *locations = [ init];
NSString* myString;
myString = [ initWithData:dataForParse encoding:NSASCIIStringEncoding];
NSLog(@"data is %@", myString);
NSArray * parsedData = ;
NSLog(@"parser data %@", parsedData);
for (NSDictionary *dict in parsedData) {
NSLog(@"Value is %@", dict);
}
;
}
</code></pre>
<p>输出如下</p>
<pre><code>2014-04-30 12:44:41.828 Testing parser data (
"/Date(1399016682788+0400)/",
"/Date(1399621482788+0400)/",
"/Date(1400226282788+0400)/",
"/Date(1400831082788+0400)/",
"/Date(1401435882788+0400)/"
)
2014-04-30 12:44:41.829 Testing Value is /Date(1399016682788+0400)/
2014-04-30 12:44:41.829 Testing Value is /Date(1399621482788+0400)/
2014-04-30 12:44:41.829 Testing Value is /Date(1400226282788+0400)/
2014-04-30 12:44:41.830 Testing Value is /Date(1400831082788+0400)/
2014-04-30 12:44:41.830 Testing Value is /Date(1401435882788+0400)/
2014-04-30 12:44:41.830 Testing finishDownloading
</code></pre>
<p>如何从 NSDictionary 获取 NSString 中的时隙?</p>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可能需要稍微调整一下,但这是我在这类日期中使用的:</p>
<p><strong>头文件</strong></p>
<pre><code>@interface NSDate (JSON)
+ (NSDate *)dateFromJSON:(NSString *)dateString;
@end
</code></pre>
<p><strong>实现</strong></p>
<pre><code>#import "NSDate+JSON.h"
@implementation NSDate (JSON)
+ (NSDate *)dateFromJSON:(NSString *)dateString {
if (dateString == nil || ]) {
return nil;
}
NSString *header = @"/Date(";
NSRange headerRange = ;
if (headerRange.location != 0) {
return nil;
}
NSString *footer = @")/";
NSRange footerRange = ;
if (footerRange.location == NSNotFound || footerRange.location + footerRange.length != dateString.length) {
return nil;
}
NSString *timestampString = ;
NSTimeInterval interval = * 0.001;
return ;
}
@end
</code></pre>
<p>此示例不包括您日期中的时区,因此您可能需要添加该时区。</p>
<p>然后像这样使用它:</p>
<pre><code>for (NSString *dateValue in parsedData) {
NSDate *date = ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 中解析 nsmutabledictionary 时间?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23382544/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23382544/
</a>
</p>
页:
[1]