Reputation: 515
I am creating a mobile app for a wordpress solution, while studying wordpress rest api, I have found a problem with the way the json schema is rendered;
while /wp-json/wp/v2/posts displays all posts but it is in this format
"title": {
"rendered": "testing rest api & #8220;tesint-restAP& #8221;"
},
How to extract the actual content from response.data.content because it came as html version with tags and such ???.
Upvotes: 3
Views: 3670
Reputation: 41
Just use content of "rendered" as value for innterHTML property of element like div. It will work.
let htmlStr = `<p><em>“Anatomy of a Bear Market”</em> by Russell Napier is a <em>“must-read</em>” manuscript. Given current market dynamics, a review seems timely. As my colleague, Richard Rosso, CFP, previously penned:</p>`
let ele = document.getElementById('target');
ele.innerHTML = htmlStr;
<div id="target"></div>
Upvotes: 0
Reputation: 638
Tip for .NET Developers
When using http://restsharp.org/ in .NET to call the API, no parsing was required on the content.
Upvotes: 1
Reputation: 6527
First, get your json data with its html tags, then
var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,"");
Upvotes: 0