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

我可以使用javascript动态编辑JSON吗?,javascript,arrays,json,parameter-passing,Javascript,Arrays,Json,Parameter Passing,嗨,我有一个json,格式如下,另存为“Data.js”,我想用one.js文件中的数组替换“Sample text” 在Data.js中 \"caption\":\"news item2\",\"text\":\"Sample text\",\"textFont\" 我想用one.js文件中新闻数组的第一个索引删除“示例文本” 那有可能吗 Data.js文件如下图所示 prx.xdata = {"cc":6, "data":{"template":{"id":"","stateid"

嗨,我有一个json,格式如下,另存为“Data.js”,我想用one.js文件中的数组替换“Sample text”

在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, "");
然后将该字符串发送到服务器并保存。

如果要“重新保存”该字符串,必须使用另一种语言,JS无法写入文件(即使用AJAX将新数据发送到.php,并将新数据保存到文件)。