Reputation: 1857
This the content of a post (wordpress) with the API plugin for WP (JSON):
"content": {
"rendered": "<p>Content post.<\/p>\n", <---- I want retrieve this
"protected": false
}
How can I do it? (Using with your example -> https://flutter.io/cookbook/networking/fetch-data/)
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
Future<Post> fetchPost() async {
final response =
await http.get('http://***********:88/WordPress/wp-json/wp/v2/posts/65');
final responseJson = json.decode(response.body);
return new Post.fromJson(responseJson);
}
class Post {
final int id;
final String title;
final String body;
final String imagen;
Post({this.id, this.title, this.body, this.imagen});
factory Post.fromJson(Map<String, dynamic> json) {
return new Post(
title: json['content'].toString(),
body: json['content'].toString(),
);
}
Upvotes: 0
Views: 1677
Reputation: 42393
You're doing this:
body: json['content'].toString(),
But if you just want the rendered
property then it should probably be this:
body: json['content']['rendered'].toString(),
However since it has HTML, you probably will also want something like flutter_html_view to render the HTML.
Upvotes: 1