2

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

在 Data.js 中

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

我想在 one.js 文件中使用我的 News 数组的第一个索引删除“SAmple text”。

那可能吗。

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);
4

1 回答 1

0

您将不得不使用正则表达式并替换

像这样:

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

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

于 2013-10-24T20:48:18.550 回答