【发布时间】:2018-11-10 01:36:15
【问题描述】:
因为我得到的答案与我想要实现的目标无关,所以我会尽可能简单。
多个单独的 json 格式相同,每个 json 都包含各个位置的信息。
我想要 powershell 做的就是这样做:
{
"Description": {
"Id": "town_breezeholme",
"Name": "Breezeholme",
"Blurb": "This quiet town on the outskirts has prospered almost
completely independently from the surrounding civilisation for nearly 200 years
due to it's vast wealth accumulated from rich, fertile farmlands, rivers and
shipping ports.",
"Authority": "Jeraxian Warriors",
},
"coords": {
"x": 66.4,
"y": -418.2,
"z": 34
},
"tags": {
"items": [
"store_jewelers",
"store_bank",
"store_general_goods",
"store_post_office",
"climate_sub_tropical"
]},
把它变成这样:
var town_breezeholme = L.marker(map.unproject([,], map.getMaxZoom()))
.bindPopup(`<h1>Breezeholme</h1><p>This quiet town on the outskirts hasprospered almost completely independently from the surrounding civilisation for nearly 200 years due to it's vast wealth accumulated from rich, fertile farmlands, rivers and shipping ports.</p> \n
<p>Climate: Sub Tropical \n
<p>Stores: Jewelers, Bank, General Goods, Post Office \n
<p>Authority: Jeraxian Warriors `);
但每一个都有几百次。我想要的只是我可以复制并粘贴到我现有的 html 文件中,这样我就不必自己为每个位置写出上述内容。
您可以忽略坐标,我不想要该信息并且我不需要标记数组,我将自己放入标记数组,因为它们的坐标与标记数组不同。
【问题讨论】:
-
哪个部分是powershell?
-
如果我是你,我会忘记 powershell。在您的网络服务器上上传 json 文件,并使用 ajax 请求(我推荐 axios)来获取它们。类似于
axios.get('jsonfiles/file1.json').then(function(response){ var town_XXtown_name = L.marker(map.unproject([response.data.coords.x, response.data.coords.u], map.getMaxZoom())).bindPopup(`<h1>${response.data.Description.Name}</h1>`);的东西(不完整,但我想你明白了。)'` jQuery 也有一个 [.get()] 如果它更熟悉的话。同样的事情(jquery 做了 1000 件事情,axios 只做 ajax 请求)。 -
我只知道 powershell 将是提取此类信息的绝佳候选者,因为我过去使用过类似的查询功能,但仅适用于单点数据。任何可以做到的都可以,我只知道 powershell 能够做到并且非常常用。我想要powershell做的就是读取json,并打印出信息,但不仅仅是给我每个位置及其信息的列表,而是在我放入的示例js代码中插入相关点到需要它们的位置操作
-
感谢 ippi,但我根本不想做。我不希望不断查询服务器上的 350 个 json。它们包含完成我想做的任务所需的数据的 100 倍。我只需要示例中列出的数据,而不需要 350 个 json 中的 3-600 行文本。我知道我要问的对powershell来说很简单,而且可以做到,我过去看过其他人的最终结果,只是不知道该怎么做。另外,您似乎错过了整点。使用您的示例,我仍然需要为每个标记输入该代码,powershell 可以打印该信息并将其粘贴到我的 html
-
好吧,我明白你的意思了,我在阅读有关 powershell 和 convertTo-json 时学到了一两件事。只是说,javascript 和 json 就像面包和黄油。 Powershell 显然是这里的开销。我可以建议一个节点脚本吗? (对不起!)
标签: javascript json powershell