gpt4 book ai didi

javascript - JSON 文件中缺少值

转载 作者:行者123 更新时间:2023-11-28 09:19:45 25 4
gpt4 key购买 nike

代码创建如下:

function create_story_json_file()
{
//Update the last edited page:

img_dataURLs[current_page]= drawing_plate.toDataURL("image/png");
create_display_img_url(current_page);

var page_num= total_page_num; //Story total page number
var page_cont= new Array();
var page_view= new Array();

//Page View:( as the pages is clicked, the page views have to be shown.
page_view= display_img_dataURL;


var img_data_URL; //if it's a variable only, you have to assign the first value in the declaration, or the tag would disappear.
var stamp_arr= new Array();
var rec_arr= new Array();
var background_msc;


//For each Story:
alert("total_page_num :"+ total_page_num );
for(var p_number=0 ; p_number < total_page_num ; p_number++)
{
img_data_URL= img_dataURLs[p_number];

//Stamp
stamp_arr= []; //reset.
var stamp_arr_for_current_page= stamp_for_all_pages[ p_number ].arr;
for(var stamp_num= 0; stamp_num < stamp_arr_for_current_page.length ; stamp_num++)
{
stamp_arr.push( stamp_arr_for_current_page[stamp_num].get_stmp_json_obj );

}
alert("stamp_arr.length is:" + stamp_arr.length);
//Rec:
rec_arr= [];
var rec_objs_at_certain_page= records_pages_arr[ p_number ].rec_objs;
for(var rec_num= 0; rec_num < rec_objs_at_certain_page.length; rec_num++)
{
rec_arr.push( rec_objs_at_certain_page[ rec_num ].get_rec_json_obj ); //check if rec_objs_at_certain_page[ rec_num ] is a rec_object!
}
alert("rec_arr length is: " + rec_arr.length);
//Background_music:
var bgr_msc_in_certain_page= back_ground_music_arr[ p_number ];
alert ("bgr_msc_in_certain_page.created" + bgr_msc_in_certain_page.created);
background_msc= bgr_msc_in_certain_page.get_bgr_msc_json_obj;





var page_content_json_obj= {
img_data_url: img_data_URL,
stamp:stamp_arr,
record: rec_arr,
bgr_msc: background_msc
}

page_cont.push(page_content_json_obj);


}


var story_json_obj= {

page_number: page_num,
page_content: page_cont,
page_img_view: page_view

}

//Change to JSON String and write it to the file.
story_json_str= JSON.stringify(story_json_obj);
}

我很困惑为什么结果 JSON 字符串:story_json_str 会是:

{"page_number":1,
"page_content":[{"img_data_url":"data:image/base64......lots of character"}]}

没有别的,“page_content”中的“stamp”、“record”和“bgr_msc”在哪里?
为什么“page_img_view”也消失了?
为什么他们会错过?

请解释并更正代码。

Ps:我在Android系统上工作,通过HTML5的功能将JSON字符串存储到文件中。我没有可用的调试平台...

最佳答案

最终我发现了问题所在。

background_msc= bgr_msc_in_certain_page.get_bgr_msc_json_obj;

由于 get_bgr_msc_json_obj 是类中的函数,因此我需要编写get_bgr_msc_json_obj()。缺少括号将不会调用该函数。

这两个工具:get_rec_json_objget_stmp_json_obj犯了同样的错误。
多么愚蠢的错误。

关于javascript - JSON 文件中缺少值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15185298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com