我有这个JSON:
{
"Id": "1",
"translations": [
{
"locale": "en",
"shortName": "Cologne",
"longName": "FC Cologne"
},
{
"locale": "tr",
"shortName": "Köln",
"longName": "Köln"
},
{
"locale": "de-de",
"shortName": "Köln",
"longName": "1. FC Köln"
},
{
"locale": "nl-nl",
"shortName": "1 FC Köln",
"longName": "1 FC Köln"
},
{
"locale": "cs",
"shortName": "1. FC Köln",
"longName": "1. FC Köln"
},
{
"locale": "it",
"shortName": "Colonia",
"longName": "Colonia"
}
],
"name": "1. FC Cologne",
"d": 2
}
我希望得到一个使用JSON查询的数组:(所有语言环境值的前两个字符):
[ "恩&#34 ;, " TR&#34 ;, "德&#34 ;, " NL&#34 ;, " CS&#34 ;, "它" ]
当我使用此查询时:
$.translations[*].locale
结果是:(不需要de-de和nl-nl,我想要de和nl):
[ "恩&#34 ;, " TR&#34 ;, "去德&#34 ;, " NL-NL&#34 ;, " CS&#34 ;, "它" ]
如果使用此JSON查询:
$.translations[*].locale[0]
它给了我所有的第一个字符:
[ " E&#34 ;, " T&#34 ;, " d&#34 ;, " N&#34 ;, " C&#34 ;, " I" ]
有没有查询可以给我我想要的结果?我将不胜感激任何帮助!我在这里检查我的JSON查询:http://www.jsonquerytool.com/
答案 0 :(得分:0)
Javascript查询:input.translations.map(x => x.locale.slice(0,2))
在此尝试:http://www.jsonquerytool.com/#/JavaScript
选择Query type
= JavaScript