我目前正在使用Angular 4开发一个应用程序。我想知道是否可以将地图转换为角度为json? 这是我的地图结构
selectedLanguageDetails.set("languageName", element.languageName);
selectedLanguageDetails.set("languageCode", element.languageCode);
selectedLanguageDetails.set("internalId", element.internalId);
json结构
"languages": [
{
"internalId": 101,
"languageCode": "ms",
"languageName": "Malay"
}
],
答案 0 :(得分:2)
要转换为对象 - 将Map展开以获取[key,value]对的数组,并将Array#reduce扩展到对象。
转换为字符串 - 使用Array#map将每对转换为字符串,而不是使用简化,并Array#join结果:
DBHandler

答案 1 :(得分:1)
要将Map转换为JSON对象或字符串,可以使用以下代码。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// leave here only window creation
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
self.window = window
}
}
// ... other code here
func sceneWillEnterForeground(_ scene: UIScene) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let contentView = ContentView().environment(\.managedObjectContext, context)
let controller = UIHostingController(rootView: contentView)
window?.rootViewController = controller
window?.makeKeyAndVisible()
}