当前,我们使用URL编码的嵌入式JSON生成可共享的URL。看起来很好吃:http://example.com/%2F%23start%3D%7B%22version%22%3A%220.0.04%22%2C%22initSources%22%3A%5B%22init%2Fnm.json%22%2C%7B%22catalog%22%3A%5B%7B%22name%22%3A%22Thing%201%22%2C%22items%22%3A%5B%7B%22name%22%3A%22Fnerp%22%2C%22items%22%3A%5B%7B%22name%22%3A%22Background%22%2C%22nowViewingIndex%22%3A0%2C%22isEnabled%22%3Atrue%2C%22isShown%22%3Atrue%2C%22isLegendVisible%22%3Atrue%2C%22opacity%22%3A0.6%7D%5D%7D%5D%7D%5D%2C%22catalogOnlyUpdatesExistingItems%22%3Atrue%7D%2C%7B%22initialCamera%22%3A%7B%22west%22%3A149.8687452406318%2C%22south%22%3A-27.849159445374482%2C%22east%22%3A154.32276951323334%2C%22north%22%3A-24.936526601352618%2C%22position%22%3A%7B%22x%22%3A-5351310.197047934%2C%22y%22%3A2833880.2585505643%2C%22z%22%3A-2987073.4882188127%7D%2C%22direction%22%3A%7B%22x%22%3A0.7925475007291486%2C%22y%22%3A-0.4197074423977381%2C%22z%22%3A0.44239588818605585%7D%2C%22up%22%3A%7B%22x%22%3A-0.3909589511624161%2C%22y%22%3A0.20703917597862256%2C%22z%22%3A0.8968198693807059%7D%7D%2C%22homeCamera%22%3A%7B%22west%22%3A105.00000000000001%2C%22south%22%3A-45%2C%22east%22%3A155%2C%22north%22%3A-5%7D%7D%5D%7D
是否有某种方案(带有Javascript库)可以更容易地做到这一点?例如,编码:
{ "thing": { "a": [1,2], "b": 4.0 }, "foo": "bar" }
如
//(thing/(a*(1,2),b*4.0),foo*'bar')
或者其他的东西。
最佳答案
啊,有了更持久的谷歌搜索,看起来就是这样:https://github.com/sage/jsurlnpm install jsurl
JSON:{"name":"John Doe","age":42,"children":["Mary","Bill"]}
JSURL:~(name~'John*20Doe~age~42~children~(~'Mary~'Bill))
JSON + URL编码:%7B%22name%22%3A%22John%20Doe%22%2C%22age%22%3A42%2C%22children%22%3A%5B%22Mary%22%2C%22Bill%
就我而言,那就是:
console.log(jsurl.stringify({"version":"0.0.04","initSources":["init/nm.json",{"catalog":[{"name":"Thing 1","items":[{"name":"Fnerp","items":[{"name":"Background","nowViewingIndex":0,"isEnabled":true,"isShown":true,"isLegendVisible":true,"opacity":0.6}]}]}],"catalogOnlyUpdatesExistingItems":true},{"initialCamera":{"west":149.8687452406318,"south":-27.849159445374482,"east":154.32276951323334,"north":-24.936526601352618,"position":{"x":-5351310.197047934,"y":2833880.2585505643,"z":-2987073.4882188127},"direction":{"x":0.7925475007291486,"y":-0.4197074423977381,"z":0.44239588818605585},"up":{"x":-0.3909589511624161,"y":0.20703917597862256,"z":0.8968198693807059}},"homeCamera":{"west":105.00000000000001,"south":-45,"east":155,"north":-5}}]}));
~(version~'0.0.04~initSources~(~'init*2fnm.json~(catalog~(~(name~'Thing*201~items~(~(name~'Fnerp~items~(~(name~'Background~nowViewingIndex~0~isEnabled~true~isShown~true~isLegendVisible~true~opacity~0.6))))))~catalogOnlyUpdatesExistingItems~true)~(initialCamera~(west~149.8687452406318~south~-27.849159445374482~east~154.32276951323334~north~-24.936526601352618~position~(x~-5351310.197047934~y~2833880.2585505643~z~-2987073.4882188127)~direction~(x~0.7925475007291486~y~-0.4197074423977381~z~0.44239588818605585)~up~(x~-0.3909589511624161~y~0.20703917597862256~z~0.8968198693807059))~homeCamera~(west~105.00000000000001~south~-45~east~155~north~-5))))
关于json - 将JSON可读地嵌入URL中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30042208/