You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Flutterwave API返回的JSON对象中提取data字段至JSON映射

提取Flutterwave API返回JSON中的"data"字段

你拿到的是标准JSON对象,顶层包含data、message、status三个字段,其中data对应的值是一个嵌套的子对象。下面是几种常用语言的提取方法:

先看原始返回的JSON:

{"data": {"response_code": "02","response_message": "Transaction in progress","flw_ref": "MockFLWRef-1676466720721","order_ref": "URF_1676466720564_5499435","account_number": "0067100155","account_status": "active","frequency": 1,"bank_name": "Mock Bank","created_at": 1676466720721,"expiry_date": 1676466720721,"note": "Mock note","amount": "NaN"},"message": "Virtual account created","status": "success"}

常用实现方式

JavaScript/Node.js

先把JSON字符串转成JS对象,再直接读取data属性:

// apiResponse是API返回的JSON字符串
const apiResponse = '{"data": {"response_code": "02","response_message": "Transaction in progress",...}}';
const parsedObj = JSON.parse(apiResponse);
const dataContent = parsedObj.data; // 这就是你要的data字段内容

Python

用内置json模块解析成字典,再通过键名取值:

import json

# response_text是API返回的JSON字符串
response_text = '{"data": {"response_code": "02","response_message": "Transaction in progress",...}}'
parsed_dict = json.loads(response_text)
data_content = parsed_dict['data']

Dart(Flutter环境)

用dart:convert包解析成Map,再提取data:

import 'dart:convert';

void handleApiResponse() {
  String apiResponse = '{"data": {"response_code": "02","response_message": "Transaction in progress",...}}';
  Map<String, dynamic> parsedData = jsonDecode(apiResponse);
  Map<String, dynamic> dataContent = parsedData['data'];
}

核心逻辑很简单:不管用哪种语言,先把API返回的JSON字符串解析成对应语言的映射/对象类型,再通过data这个键名直接取出对应的值即可。取出的data本身也是一个嵌套对象,你可以直接用键名访问它的子属性(比如dataContent.response_code或者dataContent['response_code'])。

内容的提问来源于stack exchange,提问作者Honey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 21:55:49