我试图将地图转换为人类可读的字符串。
所以,让我们说我有这张地图:
Map<String, String> map = { "foo": "lorem", "bar": "ipsum" };
我想将其转换为以下字符串,包括缩进:
{
"foo": "lorem",
"bar": "ipsum"
}
答案 0 :(得分:7)
使用:var hiw = require("hiw-api");
var apiKey = "da45e11d07eb4ec8950afe79a0d76feb";
var api = new hiw.API(apiKey);
var http = require("http");
exports.index2 = function (req, res) {
var rawresponse;
var founderror;
var indicatorDescription;
var locales;
//var allinidcatorsURL = '/Indicators/ { page }?Key= { key }';
//var filter = new hiw.Filter()
// .addEqual(hiw.Locale.Fields.ScriptFullName, "Arkansas");
hiw.Synchronizer.sync([
hiw.IndicatorDescription.getByID(279, api, function (data, response, error) {
indicatorDescription = data;
console.log(indicatorDescription.fullDescription);
console.log(indicatorDescription);
title = "Express"; //response: rawresponse, error: founderror
}),
hiw.Locale.getAll(api, function (data, response, error) {
locales = data; //Array of Locale
//console.log(locales);
})
], function (data) {
res.sendfile('./views/index.html');
//res.json(locales);
});
};
答案 1 :(得分:0)
使用此代码,您可以将地图转换为JSON字符串。
import "dart:convert";
var mapInJsonString = json.encode(map);