2016-10-28 53 views
0

私はJSONにHTMLタグとエンティティを持っていますが、私はそれを私のアプリにどのように表示するのか分かりません。私は新しい行を削除しようとしましたが、htmlエンティティのデコードを試みましたが、何も働かなかった。以下 HTMLデータを持つJSONを表示するにはどうすればよいですか?

は、私が持っているJSONの例である:実際には2に近づくある

{"Jobdesc":[{"jobid":"12281","job_title":"IOS Developer for Noida Location Job","job_desc":"<p><strong>Job Description</strong><br /> 

Dear Candidate <br /> 

I have an opening for IOS Developer for Noida Location for leading IT company. pli\ease find the JD below-<br /> 

JOB DESCRIPTION :-<br /> 

Industry :- IT <br /> 

Experience :- Min 1 Year<br /> 

Position :- IOS Developer<br /> 

Location :- Noida<br /> 

 <br /> 

<strong>Job Responsibility :- </strong><br /> 

 <br /> 

Design and build advanced applications for the iOS platform<br /> 

Collaborate with cross-functional teams to define, design, and ship new features</p> 



<p>Working experience in iOS development<br /> 

Have published one or more iOS apps in the app store<br /> 

A deep familiarity with Objective-C and Cocoa Touch<br /> 

Experience working with iOS frameworks such as Core Data, Core  Animation, Core Graphics and Core Text<br /> 

 If you are interested in the above mentioned JD kindly share your resume with me and contact me on :-<br /> 

 <br /> 

Thanks And Regards<br /> 

Pal Mittal<br /> 

Contact no :- 9200272001<br /> 

Email ID :- [email protected]<br /> 

 <br /> 

 <br /> 

Functional Area: Web/Mobile Technologies <br /> 

Industry: IT - Software <br /> 

Skills: IOS ipad <br /> 

Other Skills: IOS Developer Iphone Developer IOS Application Developer iphone Application Developer iphone<br /> 

 <br /> 

Recruiter details <br /> 

Company Name: Employment Solution<br /> 

Email: [email protected]<br /> 

Telephone: 9200272001</p> 

","job_role":"IOS Developer","job_exp":"1-4 year","job_education":"MCA","job_location":"Delhi","job_address":"Delhi","j ob_company_name":"India Shine Employment Solution","job_company_url":"www.india- shine.in","job_company_email":"[email protected]","job_status":""}]} 
+0

実際には上記のjsonでは不可能ですので、パーサーはこれを解析することはできません。例えば 'br /'どのパーサーがそのブレークタグを認識するのですか? –

+0

@Sharpkitsうん!私はこのようなJSONレスポンスが多すぎるので、HTMLエンティティをコーディングしてデコードすることで、何とかそれらの多くを管理していたと思っていました。これで例外処理を使用できますか? –

+0

あなたはどのくらいあなたが解析することができたかについての詳細を教えてください。あなたが見せたい出力ディスプレイは何ですか? –

答えて

2

アプローチ1

コード

@interface NSAttributedString (HTML) 
+ (instancetype)attributedStringWithHTMLString:(NSString *)htmlString; 
@end 

@implementation NSAttributedString (HTML) 
+ (instancetype)attributedStringWithHTMLString:(NSString *)htmlString 
{ 
    NSDictionary *options = @{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType, 
           NSCharacterEncodingDocumentAttribute :@(NSUTF8StringEncoding) }; 

    NSData *data = [htmlString dataUsingEncoding:NSUTF8StringEncoding]; 

    return [[NSAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil]; 
} 

@end 

使用

NSString *cleanString = [[NSAttributedString attributedStringWithHTMLString:question.title] string]; 

アプローチ2

NSString category for XMLEntitiesをチェックしてください。 (すべてのHTML文字参照を含む)は、XMLエンティティをデコードする方法、エンコードXMLエンティティ、タグを除去し、文字列から改行や空白を削除があります:

- (NSString *)stringByStrippingTags; 
- (NSString *)stringByDecodingXMLEntities; // Including all HTML character references 
- (NSString *)stringByEncodingXMLEntities; 
- (NSString *)stringWithNewLinesAsBRs; 
- (NSString *)stringByRemovingNewLinesAndWhitespace; 
0

あなたがのUIWebViewを使用して、このようにそれを表示することができます

let htmlString = //HTML String  
webView.delegate = self 
webView.scalesPageToFit = true 
webView.contentMode = .scaleAspectFit 
webView.loadHTMLString(htmlString, baseURL: nil) 
関連する問題