简体   繁体   English

如何通过有效载荷制作json文件

[英]How to make json file by a payload

I am using Mobx on ReactJs. 我在ReactJs上使用Mobx。
When I get the payload by mobs state, it gives weird json or array like below code. 当我通过暴民状态获得有效载荷时,它会给出奇怪的json或数组,如以下代码所示。
For example, I need 'al' like json file. 例如,我需要像json文件这样的“ al”文件。 But it doesnt work due to 'P' in the front of JSon type. 但是由于JSon类型前面的“ P”,它不起作用。
How can it be edit to make a normal json type? 如何进行编辑以制作普通的json类型?

P {G: Array(0), l: "AIzaSzyNbEXjtG475I", o: "[DEFAULT]", u: "cool-insure-bds6a.firebaseapp.com", c: bas, …}

This string representation (with the leading 'P') is only appearing when you're converting your object to a string (with, for example, console.log ). 仅在将对象转换为字符串(例如,使用console.log )时,才会出现此字符串表示形式(带有“ P” console.log )。

Use JSON.stringify(a) in order to get a valid JSON string, which you can then write to a file or do something else with it. 使用JSON.stringify(a)可以获取有效的JSON字符串,然后您可以将其写入文件或对其进行其他操作。

If you want to get back to an array from that string, use JSON.parse(str) . 如果要从该字符串返回数组,请使用JSON.parse(str)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM