在我的React Native应用程序中,我正在获取包含原始html标签的json数据。如何从中删除html标签?以下是我得到的json响应
[{
"data": {
"course": {
"id": 2864,
"name": "2. Understanding India’s economic transition",
"date_created": 1506154480,
"status": "publish",
"price": false,
"price_html": "FREE",
"total_students": 0,
"seats": "",
"start_date": false,
"average_rating": 0,
"rating_count": 0,
"featured_image": "https://www.mywebsite.com/lms/wp-content/themes/wplms/assets/images/avatar.jpg",
"categories": [],
"instructor": {
"id": "22",
"name": "aami",
"avatar": "https://www.mywebsite.com/lms/wp-content/uploads/2017/11/favicon.png",
"sub": ""
},
"menu_order": 0
},
"description": "<p style=\"text-align: justify;\">India is undergoing an economic, social and technological transformation. Perhaps no other phase is going to be as critical as the present one in shaping the future of the country as well as determining the welfare of the people. The economic transition is the vital ingredient of these overall change. Faster growth accompanied by industrial sector expansion, skill addition to the people, creation of quality infrastructure etc. will fuel this growth phase.</p>\n<p style=\"text-align: justify;\">For understanding how important is the present development phase, we have to adopt a historical and comparative study. Following factors helps us to understand the present development phase of India.</p>\n\n<ol style=\"text-align: justify;\">\n \t<li><strong>Achievement of higher growth rate as a middle-income economy. </strong></li>\n</ol>\n<p style=\"text-align: justify;\">India at present is a lower middle-income economy and has to become a high-income economy undergoing a rapid growth phase extending at least three decades.</p>\n<p style=\"text-align: justify;\">Most important narrative about the Indian economy is that it is the third largest in the world in terms of Purchasing Power Parity GDP. But a superior way to asses a country’s development is to consider per capita income. The widely used ranking about countries’ economic position is that of the World Bank’s GDP Per capita (constant US $) and the data for 2016 shows that India’s per capita income is $1861 compared to China’s $ 6994.</p>\n<p style=\"text-align: justify;\">Table: Categorization of countries by World Bank</p>\n\n<table>\n<tbody>\n<tr>\n<td width=\"198\"><strong>Category</strong></td>\n<td width=\"318\"><strong>PCI as on 2015 in constant US Dollar</strong></td>\n</tr>\n<tr>\n<td width=\"198\">Low Income Economy</td>\n<td width=\"318\">$ 1025 or less</td>\n</tr>\n<tr>\n<td width=\"198\">Middle Income Economy\n\n(India - $ 1861)</td>\n<td width=\"318\">$1026 to $4035 (Lower Middle Income)\n\n$4036 to $12475 (Upper Middle Income)</td>\n</tr>\n<tr>\n<td width=\"198\">Higher Income Economy</td>\n<td width=\"318\">$ 12476 and above</td>\n</tr>\n</tbody>\n</table>\n<p style=\"text-align: justify;\">According to World Bank metrics, a country with less than $1045 is considered as low-income economy whereas one with a PCI of $12736 or higher is considered as a higher income economy. Higher income means higher standard of living. India is at the bottom of the lower middle-income economies and has to achieve higher economic growth, structural changes including industrialisation to raise per capita income near to the $12736 mark in the long run. This is what the country has to achieve through the transition.</p>\n\n<ol style=\"text-align: justify;\" start=\"2\">\n \t<li><strong> Industrial sector expansion</strong></li>\n</ol>\n<p style=\"text-align: justify;\">There are several factors that drives the economy to prosperity. Per capita income is just a monitored goal. How it can be raised is through achieving more productivity and employment generation in the sectors that can create big changes is decisive element for the country’s transition. Here comes the role of industrial sector. The industrial sector is known for generating huge employment with minimum skill addition. Similarly, no other sector has higher level of tradability as the industrial sector (means a country can earn big income through exports). Graduating to an expanded services sector without undergoing industrialisation will be self-defeating and unsuitable to a big economy like India. Depending on services sector for exports will not reward as other countries like to protect their services sector from the inflow of India’s skilled persons. If India can increase the contribution of the industrial sector in GDP from the present 30 per cent to say 40-45%, it implies that sizable income and employment are created in the sector.</p>\n\n<ol style=\"text-align: justify;\" start=\"3\">\n \t<li><strong> Skilling the people when demography favours.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">India has the largest number of young people in the world besides having largest workforce age group population. This situation is expected to remain till 2045. Now, youth means higher ability to produce, consume and thus stimulate overall economic activities. As in the case of an individual, better things happen for an economy when it is young.</p>\n\n<ol style=\"text-align: justify;\" start=\"4\">\n \t<li><strong> Infrastructure generation.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">Infrastructure is the platform for fueling growth. The government has launched several programmes to build quality infrastructure to assist economic transformation. In the industrial sector, there is the industrial corridor project; in transportation – there is the NHDP, PMGSY, Bhartamala, Sagarmala etc. Similarly, digital infrastructure is undergoing a qualitative improvement along with the education sector.</p>\n\n<ol style=\"text-align: justify;\" start=\"5\">\n \t<li><strong> Building invention and Innovation.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">Development is dynamic and present day developing economies can’t achieve development with the strategy of the past. Fourth industrialisation, robotics, artificial intelligence etc., proved that industrialisation is not labour oriented. Here, Countries like China with the aid of superior technology with its sizable labour force can produce and supply goods to the entire world. Competing in the new age industrial sector need good technological adaptation and a progressive national invention and educational systems.</p>\n\n<ol style=\"text-align: justify;\" start=\"6\">\n \t<li><strong> Easing of Doing Business.</strong></li>\n</ol>\n<p style=\"text-align: justify;\">India’s business environment is historically suffocated by excess regulations and slow bureaucratic functions that are unsuitable for enterprise development.. But in recent years, institutional reforms are taking place and development blocking regulations are in the process of elimination.</p>\n<p style=\"text-align: justify;\">Development has become a major theme of the government and every issue related with economic prosperity are sophisticatedly addressed. Improvements in all the above field is slowly yielding results. Despite the adverse global slowdown and anti-globalisation headwinds, India continues to be the fastest growing large economy.</p>",
"curriculum": false,
"reviews": [],
"instructors": [{
"id": "22",
"name": "tojo",
"avatar": "https://www.mywebsite.com/lms/wp-content/uploads/2017/11/favicon.png",
"sub": "",
"average_rating": 0,
"student_count": 0,
"course_count": "0",
"bio": false
}],
"purchase_link": false
},
"headers": [],
"status": 200
}]
我在卡片中列出description
。那么如何删除html标签呢?请帮忙..有办法做到这一点吗?
答案 0 :(得分:10)
这个怎么样?
const regex = /(<([^>]+)>)/ig;
const result = data.description.replace(regex, '');
答案 1 :(得分:1)
我也在我的应用中遇到了这个挑战。 在尝试了几个库之后,我想建议你react-native-render-html
它允许您向Native组件提供“html”并将简单文本作为输出。 您还可以自定义每个标记以赋予它们特定的样式或忽略其中的一些。
它不需要您使用“反应链接”使其工作,因此您也可以在您的世博会应用中使用它。
希望它有所帮助。