这是带有WP(JSON)API插件的帖子(wordpress)的内容:
"content": {
"rendered": "<p>Content post.<\/p>\n", <---- I want retrieve this
"protected": false
}
我该怎么办? (与您的示例一起使用 - &gt; 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(),
);
}
答案 0 :(得分:1)
你这样做:
body: json['content'].toString(),
但是如果你只想要rendered
属性,那么应该是这样的:
body: json['content']['rendered'].toString(),
但是,由于它有HTML,您可能还需要flutter_html_view之类的内容来呈现HTML。