2013-02-13 1 views
0

plist 파일을 내 서버에서 다운로드하여 사용 가능한 NSDictionary로 변환하는 것에 대해 많은 질문을 여기에서 확인했습니다. 나는 PLIST 파일에서 만든 NSDictionaryNSLog 어떤 이유로, 나는 콘솔이 얻을 : http://www.faithlifefellowship.us/iOS/sermons.plistplist as NSDictionary returns (null)

코드 :

NSDictionary* plist = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://www.faithlifefellowship.us/iOS/sermons.plist"]]; 

NSLog(@"%@",plist); 

Timestamp: (null) 

나는 그것이 실제 파일 것을 알고

무엇이 문제입니까?

plist 파일이 축소되었다는 사실과 관련이 있습니까?

UPDATE :

다음 코드로 파일을 가져 오기 :

NSString* pl = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.faithlifefellowship.us/iOS/sermons.plist"] encoding:NSUTF8StringEncoding error:nil]; 

NSLog(@"%@",pl); 

반환 : 계속적으로

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>1</key><array><integer>1</integer><string>I've Been Redeemed</string><string>Ive Been Redeemed</string><array><string></string></array><array><string>03/20/09</string><string>04/02/09</string><string>04/10/09</string><string>04/24/09</string><string>05/13/09</string><string>05/23/09</string><string>06/06/09</string><string>06/13/09</string><string>06/20/09</string></array><string>http://faithlifefellowship.us/Sermons/Banners/Banner-IBR.png</string><integer>9</integer><array><string>Many Christians allow things in their lives, not realizing that they have been redeemed from them and because of ignorance of God's Word, do not walk in total freedom. This series will set you free in every area of your life!</string><string>It is important to be able to differentiate between a curse in our lives and suffering tribulation for the Lord's sake.</string><string>The same exact blessing that was on Abraham's life is now on our lives because of Jesus Christ. Don't let ignorance or unbelief keep you from all that God has for you!</string><string>Well, I guess God wants me to be sick to teach me a lesson, ever heard someone say that? Well that does not work EVER in the light of God's Word. Gal 3:13 Christ HAS redeemed us...</string><string>As we age the world says that we get weaker mentally, but God's Word does not agree with this. Part of what we have been redeemed from is an unsound and unstable mind.</string><string>Get up early, work late, still nothing ever seems to go your way why? Becasue of the curse. The Good News is that we have been redeemed from loss and failure in our lives!</string> 

ㅋ ㅋ ㅋ ㅋ ㅋ ㅋ 그리고 ... 은 모든있다

+0

plist는 유효한 plist입니까? 또한 파일을 NSData로 가져 와서 문자열로 변환하고, NSLog에서 (내용을 보려면) NSData에서 사전을 만들려고 시도 할 수 있습니다. – Ondrej

+0

그게 중요합니다. 나는 XCode에서 템플릿 plist를 만들고 내 서버에서 PHP로 새로운 plist를 만드는 데 사용 했으므로 유효하다고 믿는다. ... – David

+0

NSData로 다운로드하고 실제 내용을 보려면 문자열로 변환 해 보라. 종종 그것은 URL이나 그와 유사한 문제와 같이 짜증나게 어리 석습니다. 데이터를 다시 가져 오면 알려주세요. – Ondrej

답변

4

이스케이프 처리되지 않은 앰퍼샌드가 있습니다 (예 : 'Pt 1 & 2')이 제한되어 있습니다. 당신은 당신의 서버에 &amp;로 교체, 또는있는 NSString에 파일의 내용을 다운로드 한 다음 &amp;&를 교체해야 하나 :

NSString *error; 
NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.faithlifefellowship.us/iOS/sermons.plist"] 
             encoding:NSUTF8StringEncoding 
              error:&error]; 

str = [str stringByReplacingOccurrencesOfString:@" & " withString:@" &amp; "]; 
NSData *plistData = [str dataUsingEncoding:NSUTF8StringEncoding]; 

NSPropertyListFormat format; 
NSDictionary *plist = [NSPropertyListSerialization propertyListFromData:plistData 
                 mutabilityOption:NSPropertyListImmutable 
                   format:&format 
                 errorDescription:&error]; 

플러스, 태그 매칭에 큰 문제가있다. 당신은 plist를 유효하게 할 수 있습니다 http://www.xmlvalidation.com

+0

그냥 실제로 그것을 지적하고 싶었 :) :) ... plist가 유효하지 않습니다,이 답변은 정확합니다! – Ondrej

+0

만세! 작동 중! 감사! – David