我正在使用Google Apps脚本和EmbeddedChartBuilder在我的Google电子表格中嵌入折线图.手动创建这些图表时,您可以使用(非默认)选项"将列A用作标签"(其中"A"是数据范围中的第一列).我找不到从脚本中做同样的方法.从Google Visualization折线图文档中可以看出,默认情况下将第一列视为具有"域"角色; 但是EmbeddedChartBuilder似乎会覆盖它并为所有列提供"数据"角色.由于我没有明确的DataTable,我无法自己设置列角色.
我错过了这样做的方法吗?或者我是否必须将方法从EmbeddedChartBuilder切换为使用电子表格作为数据源?
charts google-visualization embedded-resource google-sheets google-apps-script
我有一个问题,我想解决,而不必花费大量的手工工作来分析作为替代.
我有2个JSON对象(从不同的Web服务API或HTTP响应返回).2个JSON对象之间存在交叉数据,它们共享类似的JSON结构,但不完全相同.一个JSON(较小的一个)就像是较大的JSON对象的子集.
我想找到两个对象之间的所有相互关联的数据.实际上,我对对象中的共享参数/属性更感兴趣,而不是每个对象的参数/属性的实际值.因为我想最终使用来自一个JSON输出的数据来构造另一个JSON作为API调用的输入.不幸的是,我没有为每个API定义JSON的文档.:(
更难的是JSON对象是巨大的.如果您通过Windows记事本打印出来,则会跨页面.另一篇涉及37页.API返回压缩为单行的JSON输出.普通文本比较没有太大作用,我必须手动重新格式化或用脚本来分解对象w /换行符等,以便文本比较工作正常.尝试使用Beyond Compare工具.
我可以进行手动搜索/ grep,但是在较小的JSON中遍历所有参数是很痛苦的.可以写代码来做,但我还要花时间去做,并测试代码是否也能正常工作.或者可能已经有一些现成的代码......
或者可以查找JSON diff类型工具.搜索了一些.碰到这些:
https://github.com/samsonjs/json-diff或https://tlrobinson.net/projects/javascript-fun/jsondiff
https://github.com/andreyvit/json-diff
都没能做我想做的事.据推测,JSON太复杂或太大而无法处理.
有关最佳解决方案的想法?或者现在可能最好的解决方案是每个参数/属性的grep手动分析?
就代码解决方案而言,任何语言都可以.我只需要一个解析器或差异工具来完成我想要的工作.
抱歉,无法与您共享JSON数据结构,可能会被视为机密.
我有一个HTML表单,并在点击提交按钮时将数据发送到php文件.
$.ajax({
url: "text.php",
type: "POST",
data: {
amount: amount,
firstName: firstName,
lastName: lastName,
email: email
},
dataType: "JSON",
success: function (data) {
console.log("ok");
$("#result").text(data);
}
});
Run Code Online (Sandbox Code Playgroud)
在PHP中:
<?php
$amount = $_POST["amount"];
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
if(isset($amount)){
$data = array(
"amount" => $amount,
"firstName" => $firstName,
"lastName" => $lastName,
"email" => $email
);
echo json_encode($data);
}
?>
Run Code Online (Sandbox Code Playgroud)
结果是[对象对象].我想要一个类似的类型:
{"Amount":"12.34", "FirstName":"Any", "LastName":"Tester", "Email":"a.test@something.com"}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我有一个从网上下载的多行字符串:
toast the lemonade
blend with the lemonade
add one tablespoon of the lemonade
grill the spring onions
add the lemonade
add the raisins to the saucepan
rinse the horseradish sauce
Run Code Online (Sandbox Code Playgroud)
我已将其分配给$INPUT,如下所示:
toast the lemonade
blend with the lemonade
add one tablespoon of the lemonade
grill the spring onions
add the lemonade
add the raisins to the saucepan
rinse the horseradish sauce
Run Code Online (Sandbox Code Playgroud)
此时,$INPUT已准备好替换到我的目标文件中,如下所示:
INPUT=$(lynx --dump 'http://example.net/recipes' \
| python -m json.tool \
| awk '/steps/,/]/' \ …Run Code Online (Sandbox Code Playgroud) 当使用json.dump保存dict时,它只是一个单行.我想让这个像人类可读的格式,如本网站的确 - https://jsonformatter.curiousconcept.com
我怎么能在python中这样做?我试图捕获pprint输出,但它是一个无效的字符串来存储JSON.
具体来说,是否有一种可接受的默认方式直接在python中执行此操作?
我正在尝试这样做:
curl localhost:3000/api/items/15/tools
这是现在的回报:
{"recipe_tools":[{"id":19,"name":"砧板","prices":{"display":"$49.99","value":"49.99"},"description":"Built最后,
......(然后像一百万行)
而且它一直在继续......
我如何漂亮地打印或真棒打印这个?我能做什么?
我正在使用他们的Python库实现Google数据源.我希望库中的响应能够使用simplejson库在另一个Python脚本中导入.
但是,即使他们的示例也没有在JSONLint中验证:
{cols:
[{id:'name',label:'Name',type:'string'},
{id:'salary',label:'Salary',type:'number'},
{id:'full_time',label:'Full Time Employee',type:'boolean'}],
rows:
[{c:[{v:'Jim'},{v:800,f:'$800'},{v:false}]},
{c:[{v:'Bob'},{v:7000,f:'$7,000'},{v:true}]},
{c:[{v:'Mike'},{v:10000,f:'$10,000'},{v:true}]},
{c:[{v:'Alice'},{v:12500,f:'$12,500'},{v:true}]}]}
Run Code Online (Sandbox Code Playgroud)
如何调整simplejson'loads'函数来导入上面的JSON?我认为主要问题是对象键不是字符串.
我宁愿不写一个正则表达式来将键转换为字符串,因为我认为这样的代码会很难维护.
我正在尝试使用simplejson将上面的json导入到python中时出现"Expecting property name:line 1 column 1(char 1)"错误.
我在php中构建一个API.此API处理来自第三方API的json消息.
我想记录无效的漂亮打印的json消息.
所以我这样做了:
error_log("test\n" . json_encode($json_string, JSON_PRETTY_PRINT));
Run Code Online (Sandbox Code Playgroud)
但是,当我查看我的日志时,json字符串打印效果不佳:
$ tailf error.log
2015-07-13 10:20:03: (mod_fastcgi.c.2701) FastCGI-stderr: test
"{\"info\":{\"status\":200,\"msg\":\"OK\"},\"response\":{\"foo\":\"bar\"}"
Run Code Online (Sandbox Code Playgroud)
我希望看到类似的东西:
$ tailf error.log
2015-07-13 10:20:03: (mod_fastcgi.c.2701) FastCGI-stderr: test
{
"info": {
"status": 200,
"msg ": "OK"
},
"response": {
"foo": "bar"
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个结果?
我有一个 json 文件。如果我在其上运行 clang-format ,它会将其格式化为代码(丑陋)。
{
"name" : "My great app",
"description" : "It's really cool.",
"version" : "0.0.1"
}
Run Code Online (Sandbox Code Playgroud)
如果我将 'foo = ' 放在文件的开头,那很好,但它不再是 json 了。
foo = {
"name" : "My great app",
"description" : "It's really cool.",
"version" : "0.0.1"
}
Run Code Online (Sandbox Code Playgroud)
如何获得 clang-format 来格式化 json 文件中的裸对象,如第二个示例所示?
我有几个(〜300,000)个单个JSON对象的文件,我想合并为一个JSON数组的文件。假设它们都在“〜/ data_files”位置,如何在Linux上执行此操作?
文件A
{
name: "Test",
age: 23
}
Run Code Online (Sandbox Code Playgroud)
文件B
{
name: "Foo",
age: 5
}
Run Code Online (Sandbox Code Playgroud)
文件库
{
name: "Bar",
age: 5
}
Run Code Online (Sandbox Code Playgroud)
示例输出:(以括号开头和结尾,并在对象之间添加逗号)
[
{
name: "Test",
age: 23
},
{
name: "Foo",
age: 5
},
{
name: "Bar",
age: 5
}
]
Run Code Online (Sandbox Code Playgroud)
我尝试过的
我知道我可以cat用来合并一堆文件,尚不确定如何对目录中的所有文件进行合并,但可以尝试解决。还试图弄清楚,我要串联的文件之间的关系,还没有看到命令。
json ×6
javascript ×3
python ×3
php ×2
ajax ×1
cat ×1
charts ×1
clang-format ×1
curl ×1
diff ×1
jquery ×1
linux ×1
logging ×1
pretty-print ×1
readability ×1
sed ×1
shell ×1
simplejson ×1