- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在单个数组中有一个 json 对象,这是一个原始文件,我删除了一些字段,现在我想改变每个条目的键值之一。这是一些 Json 示例。我想循环遍历并分割 http://www.website/wp-content/uploads/
处的 meta_value现在我的代码将每个meta_value返回为未定义,而不是拆分值,我认为这与循环更改键值并尝试在之后拆分它有关。
任何帮助将不胜感激
这是我到目前为止在最后生成 json 数据的代码
var exclusions = [
"ID", "post_author", "post_date_gmt", "post_excerpt", "comment_status",
"ping_status", "post_password", "to_ping" ,"pinged", "post_modified","post_name",
"post_modified_gmt", "post_content_filtered", "guid", "menu_order", "post_mime_type",
"comment_count", "meta_id", "post_id", "post_type", "post_status"
];
var a = JSON.parse(fs.readFileSync('final.json'));
a.forEach(obj=>{
exclusions.forEach(excl=>{
if(obj[excl] || obj[excl] === ""){
delete obj[excl];
}
if(obj["meta_value"] !== undefined){
let objTest = obj["meta_value"].split('http://www.fsd.ca/wp-content/uploads/')[1];
obj["meta_value"] = objTest;
}
});
});
console.log(a);
初始排除后的 Json
[
{
post_date: '2012-02-16 23:37:22',
post_content: `Today we worked at literacy centres. We are writing our own Three Bears story. We are reading with Mrs.Kitson, writing in our life books, working in our printing books and working on making words on the iPads. We use the apps Pocket phonics, magnet board and Montessori crosswords. We went to the library. In the afternoon we went to the gym and watched a play by Quest Theatre. It was called <span style="text-decoration: underline;">For</span> <span style="text-decoration: underline;">Art's Sake.</span> They told us that we are all artists and that we should use our imagination. We did zumba. We danced to The chihuahua song. We went to the DPA room and played different tag games. Our hearts worked hard. We had a fun day!`,
post_title: 'Hometime',
meta_value: 'http://www.fsd
.ca/wp-content/uploads/2012/02/SN850631.jpg' }, { post_date: '2012-02-21 20:39:19', post_content:'今天我们开始 build 我们的城堡。我们给它们涂上彩色的薄纸。我们正在书写我们自己的童话。我们读了《 Frog 公主童话》。我们正在制作泥龙和缝制木偶。我们去了健身房,然后就逃课了。我们在生活中写书并练习打印。我们度过了愉快的一天!', post_title: '创建城堡', 元值:'http://www.fd.ca/wp-content/uploads/2012/02/SN850649.jpg ' }, { post_date: '2012-02-23 21:30:55', post_content: '我们讨论了字母 E。E 是元音。每个单词都有一个元音。我们做了E表。我们去滑冰了。滑冰后我们喝了热巧克力。我们在新的扫盲中心工作。我们正在努力工作。我们去了音乐。我们玩了大黄蜂游戏。我们去了 DPA 房间玩标签和跳舞。我们去了中心和图书馆。我们度过了愉快的一天!', post_title: '我们有新枕头', 元值:'http://www.fds.ca/wp-content/uploads/2012/02/SN850660.jpg ' }, { post_date: '2012-02-24 19:06:39', post_content:'今天是夏威夷日。我们穿着短裤和夏天的衣服。我们制作了一张 Chicka Chicka Boom Boom 图片。我们做了花环。我们吃了面糊菠萝,还吃了芒果、菠萝、木瓜、杨桃、火龙果和椰子。我们尝试了椰子水。我们跳了 hell 边境并跳了夏威夷风格的舞蹈。我们坐在毛巾上玩数学游戏,猜杯子下面有多少糖果。我们写下了人生的书,然后去了大公园。我们度过了愉快、有趣的一天!', post_title: '夏威夷日', 元值:'http://www.ff.ca/wp-content/uploads/2012/02/SN850665.jpg ' }, ... 654 更多项目 ]
meta_value键值改变后的Json,每个值都是未定义的
[
{
post_date: '2012-02-16 23:37:22',
post_content: `Today we worked at literacy centres. We are writing our own Three Bears story. We are reading with Mrs.Kitson, writing in our life books, working in our printing books and working on making words on the iPads. We use the apps Pocket phonics, magnet board and Montessori crosswords. We went to the library. In the afternoon we went to the gym and watched a play by Quest Theatre. It was called <span style="text-decoration: underline;">For</span> <span style="text-decoration: underline;">Art's Sake.</span> They told us that we are all artists and that we should use our imagination. We did zumba. We danced to The chihuahua song. We went to the DPA room and played different tag games. Our hearts worked hard. We had a fun day!`,
post_title: 'Hometime',
meta_value: undefined
},
{
post_date: '2012-02-21 20:39:19',
post_content: 'Today we started making our castles. We painted them colourful tissue paper. We are writing our own fairy tales. We read The Princess Frog Fairy Tale. We are making clay dragons and sewing puppets. We went to the gym and skipped. We wrote in our life books an practiced our printing. We had a fun day!',
post_title: 'Creating Castles',
meta_value: undefined
},
{
post_date: '2012-02-23 21:30:55',
post_content: 'We talked about the letter E. E is a vowel. There is a vowel in every word. We did our E sheets. We went skating. We had hot chocolate after skating. We worked at new literacy centers. We are doing hard work. We went to Music. We played the bumble bee game. We went to the DPA room to play tag and dance. We went to centers and to the library. We had a fun day!',
post_title: 'We Have New Pillows',
meta_value: undefined
},
{
post_date: '2012-02-24 19:06:39',
post_content: 'Today it was Hawaii Day. We wore shorts and summer clothes. We made a Chicka Chicka Boom Boom picture. We made leis. We ate batter dipped pineapples and ate mango, pineapple, papaya, starfruit, dragon fruit and coconut. We tried coconut water. We did the limbo and danced Hawaii style. We sat on our towels and played a math game where we guessed how many candies were under the cup. We wrote in our life books and we went to the big park. We had a fun, fun day!',
post_title: 'Hawaii Day',
meta_value: undefined
},
... 654 more items
]
最佳答案
问题是您有代码可以在 exclusions.forEach()
循环内更改 obj["meta_value"]
。因此它对同一个对象运行多次。第一次,它将 'http://www.mrskitson.ca/wp-content/uploads/2012/02/SN850631.jpg'
替换为 '2012/02/SN850631.jpg '
。第二次,它在元值中找不到分隔符 'http://www.mrskitson.ca/wp-content/'
,因此 split()
返回一个只有 1 个元素的数组,并且 [1]
未定义。
将其从内循环中取出,它应该可以正常工作。
var exclusions = [
"ID", "post_author", "post_date_gmt", "post_excerpt", "comment_status",
"ping_status", "post_password", "to_ping", "pinged", "post_modified", "post_name",
"post_modified_gmt", "post_content_filtered", "guid", "menu_order", "post_mime_type",
"comment_count", "meta_id", "post_id", "post_type", "post_status"
];
var a = [
{
post_date: '2012-02-16 23:37:22',
post_content: `Today we worked at literacy centres. We are writing our own Three Bears story. We are reading with Mrs.Kitson, writing in our life books, working in our printing books and working on making words on the iPads. We use the apps Pocket phonics, magnet board and Montessori crosswords. We went to the library. In the afternoon we went to the gym and watched a play by Quest Theatre. It was called <span style="text-decoration: underline;">For</span> <span style="text-decoration: underline;">Art's Sake.</span> They told us that we are all artists and that we should use our imagination. We did zumba. We danced to The chihuahua song. We went to the DPA room and played different tag games. Our hearts worked hard. We had a fun day!`,
post_title: 'Hometime',
meta_value: 'http://www.mrskitson.ca/wp-content/uploads/2012/02/SN850631.jpg'
},
{
post_date: '2012-02-21 20:39:19',
post_content: 'Today we started making our castles. We painted them colourful tissue paper. We are writing our own fairy tales. We read The Princess Frog Fairy Tale. We are making clay dragons and sewing puppets. We went to the gym and skipped. We wrote in our life books an practiced our printing. We had a fun day!',
post_title: 'Creating Castles',
meta_value: 'http://www.mrskitson.ca/wp-content/uploads/2012/02/SN850649.jpg'
},
{
post_date: '2012-02-23 21:30:55',
post_content: 'We talked about the letter E. E is a vowel. There is a vowel in every word. We did our E sheets. We went skating. We had hot chocolate after skating. We worked at new literacy centers. We are doing hard work. We went to Music. We played the bumble bee game. We went to the DPA room to play tag and dance. We went to centers and to the library. We had a fun day!',
post_title: 'We Have New Pillows',
meta_value: 'http://www.mrskitson.ca/wp-content/uploads/2012/02/SN850660.jpg'
},
{
post_date: '2012-02-24 19:06:39',
post_content: 'Today it was Hawaii Day. We wore shorts and summer clothes. We made a Chicka Chicka Boom Boom picture. We made leis. We ate batter dipped pineapples and ate mango, pineapple, papaya, starfruit, dragon fruit and coconut. We tried coconut water. We did the limbo and danced Hawaii style. We sat on our towels and played a math game where we guessed how many candies were under the cup. We wrote in our life books and we went to the big park. We had a fun, fun day!',
post_title: 'Hawaii Day',
meta_value: 'http://www.mrskitson.ca/wp-content/uploads/2012/02/SN850665.jpg'
},
];
a.forEach(obj => {
exclusions.forEach(excl => {
if (obj[excl] || obj[excl] === "") {
delete obj[excl];
}
});
if (obj["meta_value"] !== undefined) {
let objTest = obj["meta_value"].split('http://www.mrskitson.ca/wp-content/uploads/')[1];
obj["meta_value"] = objTest
}
});
console.log(a);
关于javascript - 单个数组中的 Json 对象,需要使用 key meta_value 拆分键上的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59872458/
查看“mysqldump -d”并看到一个键是 KEY,而不是“PRIMARY KEY”或“FOREIGN KEY” 什么是关键? 示例: CREATE TABLE IF NOT EXISTS `TA
在我开始使用 Python 的过程中尝试找出最佳编码实践。我用 Pandas 写了一个 csv 到数据框阅读器。它使用格式: dataframe = read_csv(csv_input, useco
在 Flutter 中,用一个例子可以清楚地解释什么? 我的困惑是关于 key,如下面的代码所示。 MyHomepage({Key key, this.title}) : super(key: key
我在我的 Android 应用程序中使用 GCM。要使用 GCM 服务,我们需要创建 Google API key 。因此,我为 android、服务器和浏览器 key 创建了 API key 。似乎
我想在 azure key 保管库中创建一个 secret ,该 key 将具有多个 key (例如 JSON)。 例如- { "storageAccountKey":"XXXXX", "Co
尝试通过带有 encodeforURL() 的 url 发送 key 时,我不断收到错误消息和 decodefromUrl() .代码示例如下。 这是我的入口页面: key = generateSec
是否有检查雪花变体字段中是否存在键的函数? 最佳答案 您可以使用 IS_NULL_VALUE 来查看 key 是否存在。如果键不存在,则结果将为 NULL。如果键存在,如果值为 JSON null,则
我正在尝试运行此命令: sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A 但我收到一个错误: Execu
我有一个 csv 文件,我正在尝试对 row[3] 进行计数,然后将其与 row[0] 连接 row[0] row[3] 'A01' 'a' 'B02'
如何编写具有这种形式的函数: A(key, B(key, C(key, ValFactory(key)))) 其中 A、B 和 C 具有此签名: TResult GetOrAdd(string key
审查 this method我很好奇为什么它使用 Object.keys(this).map(key => (this as any)[key])? 只调用 Object.keys(this).ind
我有一个奇怪的情况。我有一个字典,self.containing_dict。使用调试器,我看到了字典的内容,并且可以看到 self 是其中的一个键。但是看看这个: >>> self in self.c
我需要在我的 Google Apps 脚本中使用 RSA-SHA256 和公钥签署消息。 我正在尝试使用 Utilities.computeRsaSha256Signature(value, key)
我是 React 的初学者开发人员,几天前我看到了一些我不理解的有趣语法。 View组件上有{...{key}},我会写成 key={key} ,它完全一样吗?你有链接或解释吗? render()
代理 key 、合成 key 和人工 key 之间有什么区别吗? 我不清楚确切的区别。 最佳答案 代理键、合成键和人工键是同义词。技术关键是另一个。它们都表示“没有商业意义的主键”。它们不同于具有超出
问题陈述:在 Web/控制台 C# 应用程序中以编程方式检索并使用存储在 Azure Key Vault 中的敏感值(例如数据库连接字符串)。 据我所知,您可以在 AAD 中注册应用,并使用其客户端
问题陈述:在 Web/控制台 C# 应用程序中以编程方式检索并使用存储在 Azure Key Vault 中的敏感值(例如数据库连接字符串)。 据我所知,您可以在 AAD 中注册应用,并使用其客户端
我正在寻找 Perl 警告的解决方案 “引用键是实验性的” 我从这样的代码中得到这个: foreach my $f (keys($normal{$nuc}{$e})) {#x, y, and z 我在
我正在为 HSM 实现 JCE 提供程序 JCE中有没有机制指定 key 生成类型例如: session key 或永久 key KeyGenerator keygen = KeyGener
我在 Facebook 上创建了一个应用程序。我已经正确添加了 keyhash 并且应用程序运行良好但是当我今天来并尝试再次运行它时它给了我这个错误。 这已经是第二次了。 Previsouly 当我收
我是一名优秀的程序员,十分优秀!