如何显示具有HTML数据的JSON?

时间:2016-10-28 10:43:01

标签: html ios objective-c json

我在JSON中有HTML标记和实体,我不知道如何在我的应用中显示它。我尝试删除新行,我尝试解码html实体,但没有任何效果。

以下是我拥有的JSON示例:

{"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 :- parul@india-shine.in<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: pal@ishine.in<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":"kumar178dilip@gmail.com","job_status":""}]}

2 个答案:

答案 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。有解码XML实体(包括所有HTML字符引用),编码XML实体,剥离标记以及从字符串中删除换行符和空格的方法:

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

答案 1 :(得分:0)

您可以使用UIWebView并将其显示如下:

postman.setGlobalVariable("IID", Math.floor(Math.random() * 100));