gpt4 book ai didi

javascript - 我可以使用 javascript 动态编辑 JSON 吗?

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

您好我有一个具有以下格式的 json 并保存为“Data.js”我想用我的 one.js 文件中的数组替换“示例文本”。

在 Data.js 中

\"caption\":\"news item2\",\"text\":\"Sample text\",\"textFont\"

我想在 one.js 文件中删除带有我的新闻数组第一个索引的“示例文本”。

这可能吗?

如下所示的Data.js文件

    prx.xdata = {"cc":6,
"data":{"template":{"id":"","stateid":""},"items":[{"left":11,"top":69,"width":298,"height":300,"type":"symbol","text":"","symbolid":1,"caption":"news container","visible":true,"scroll":"horizontal","scrollsnap":true,"pinchzoom":false,"lockdirection":true,"zindex":2001,"id":"box-6","groups":[],"hpos":"left","vpos":"top","wtype":"fixed","htype":"fixed","opacity":"1","propagateevents":false,"symbolstateid":"a8d0d79e-1921-4f7e-a229-75e5b1602881","bounce":false,"lib":"undefined"}]},"fonts":[],"grid":{"grid":{"size":50,"subdivisions":5},"gridsystem":{"portrait":{"col_number":2,"col_width":140,"gutter_width":20,"margins":10},"landscape":{"col_number":3,"col_width":140,"gutter_width":20,"margins":10}},"guides":{"custom":{"portrait":{"horizontal":[],"vertical":[]}}}},"_groupCounter":0,"savedColors":[],"iSelectedPage":0,"iSelectedTemplate":-1,"iSelectedSymbol":-1,"iSelectedState":0,"libraries":{"common":true,"icons":true,"iphone":true},"maxpageid":1,"maxsymbolid":1,"maxtemplateid":0,"project":{"statusbar":"1","navigationbar":"0","startscreenlandscape":"1","startscreen":"1","projectid":"11ac7f90-7e4c-4efe-a23c-d37aa70d7bcf"},"sort":{"pages":{"type":"default"},"templates":{"type":"default"},"containers":{"type":"default"}},"variables":{},"v5":true,"pages":[{"orientation":"portrait","statusbar":"1","navigationbar":"0","id":1,"actions":[],"title":"Screen 1","states":[{"data":"[{\"left\":11,\"top\":69,\"width\":298,\"height\":300,\"type\":\"symbol\",\"text\":\"\",\"symbolid\":1,\"caption\":\"news container\",\"visible\":true,\"scroll\":\"horizontal\",\"scrollsnap\":true,\"pinchzoom\":false,\"lockdirection\":true,\"zindex\":2001,\"id\":\"box-6\",\"groups\":[],\"hpos\":\"left\",\"vpos\":\"top\",\"wtype\":\"fixed\",\"htype\":\"fixed\",\"opacity\":\"1\",\"propagateevents\":false,\"symbolstateid\":\"a8d0d79e-1921-4f7e-a229-75e5b1602881\",\"bounce\":false,\"lib\":\"undefined\"}]","template":{"id":"","stateid":""},"title":"Default State","history":[],"background":"none","id":"6b3b49d1-c302-4035-a254-89157ce10277"}],"sort":0}],"templates":[],"symbols":[{"id":1,"title":"news container","states":[{"title":"Default State","background":"none","data":"[{\"name\":\"text\",\"type\":\"text\",\"lib\":\"common\",\"caption\":\"newsitem1\",\"text\":\"Sample text\",\"textFont\":\"sans-serif,Helvetica Neue,Arial\",\"textSize\":\"16\",\"textColor\":\"000000\",\"backgroundColor\":\"none\",\"width\":292,\"height\":257,\"textProperties\":[],\"textAlign\":\"left\",\"enableShadow\":false,\"autoResize\":false,\"left\":8,\"top\":21,\"vpos\":\"top\",\"hpos\":\"left\",\"visible\":true,\"id\":\"box-2\",\"groups\":[],\"zindex\":2001,\"wtype\":\"fixed\",\"htype\":\"fixed\",\"opacity\":\"1\"},{\"name\":\"text\",\"type\":\"text\",\"lib\":\"common\",\"caption\":\"news item2\",\"text\":\"Sample text\",\"textFont\":\"sans-serif,Helvetica Neue,Arial\",\"textSize\":\"16\",\"textColor\":\"000000\",\"backgroundColor\":\"none\",\"width\":301,\"height\":257,\"textProperties\":[],\"textAlign\":\"left\",\"enableShadow\":false,\"autoResize\":false,\"left\":300,\"top\":21,\"vpos\":\"top\",\"hpos\":\"left\",\"visible\":true,\"id\":\"box-3\",\"groups\":[],\"zindex\":2002,\"wtype\":\"fixed\",\"htype\":\"fixed\",\"opacity\":\"1\"},{\"name\":\"text\",\"type\":\"text\",\"lib\":\"common\",\"caption\":\"news item3\",\"text\":\"Sample text\",\"textFont\":\"sans-serif,Helvetica Neue,Arial\",\"textSize\":\"16\",\"textColor\":\"000000\",\"backgroundColor\":\"none\",\"width\":292,\"height\":257,\"textProperties\":[],\"textAlign\":\"left\",\"enableShadow\":false,\"autoResize\":false,\"left\":601,\"top\":21,\"vpos\":\"top\",\"hpos\":\"left\",\"visible\":true,\"id\":\"box-4\",\"groups\":[],\"zindex\":2003,\"wtype\":\"fixed\",\"htype\":\"fixed\",\"opacity\":\"1\"},{\"name\":\"text\",\"type\":\"text\",\"lib\":\"common\",\"caption\":\"news item4\",\"text\":\"Sample text\",\"textFont\":\"sans-serif,Helvetica Neue,Arial\",\"textSize\":\"16\",\"textColor\":\"000000\",\"backgroundColor\":\"none\",\"width\":298,\"height\":257,\"textProperties\":[],\"textAlign\":\"left\",\"enableShadow\":false,\"autoResize\":false,\"left\":901,\"top\":21,\"vpos\":\"top\",\"hpos\":\"left\",\"visible\":true,\"id\":\"box-5\",\"groups\":[],\"zindex\":2004,\"wtype\":\"fixed\",\"htype\":\"fixed\",\"opacity\":\"1\"}]","history":[],"dimensions":["1200","300"],"id":"a8d0d79e-1921-4f7e-a229-75e5b1602881"}],"sort":0,"customguides":{"horizontal":[],"vertical":[]},"grid":{"col_number":3,"col_width":80,"gutter_width":20,"margins":10}}]};

prx.xdata_str = JSON.stringify(prx.xdata);

最佳答案

你必须使用正则表达式并替换

像这样:

var newFile = prx.xdata_str.replace(/Sample/g, "");

然后将该字符串发送到您的服务器并保存。

关于javascript - 我可以使用 javascript 动态编辑 JSON 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19496109/

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