小编Adi*_*tel的帖子

在python2.7中将原始字符串转换为JSON对象

我正在查询PostgreSQL服务器以获取数据,并且特定json对象实际上以字符串形式返回.我试过跟随,但没有给出正确的输出:(它的ipython输出)

test
Out[103]: '{"max"=>28, "min"=>18, "custom"=>[{"id"=>"12345","name"=>"test_pur"}]}'
In[104]: test.replace("=>",":")
Out[104]: '{"max":28, "min":18, "custom":[{"id":"12345", "name":"test_pur"}]}'
In[105]: j_obj = json.dumps(test)
In[106]: j_obj
Out[106]: '"{\\"max\\"=>28, \\"min\\"=>18, \\"custom\\"=>[{\\"id\\"=>\\"12345\\", \\"name\\"=>\\"test_pur\\"}]}"'
Run Code Online (Sandbox Code Playgroud)

如何通过识别":"符号将字符串转换为json?

当我尝试"json.loads"时.以下是错误:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-12-a7562191decf>", line 1, in <module>
    data = json.loads(temp)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
    obj, …
Run Code Online (Sandbox Code Playgroud)

python json python-2.7

5
推荐指数
1
解决办法
3万
查看次数

Division of two fields in Elasticsearch

Currently i am trying to group a field based on one field and than getting sum of other fields with respect to the respective field used for grouping. I want to get a new value which needs to be division of the summed field . I will provide the current query i have :

In my query i am aggregating them based on the field ("a_name") and summing "spend" and "gain". I want to get a new field which would …

groovy elasticsearch

2
推荐指数
1
解决办法
6114
查看次数

使D3.js 2D图表图表响应

首先,我想说清楚我确实通过stackoverflow中发布的以下链接:

在d3.js中调整窗口大小时调整svg的大小

以下是jsfiddle和代码的链接:https://jsfiddle.net/adityap16/d61gtadm/8/

码-

var data = [
{"mytime": "2015-12-01T11:10:00.000Z", "value": 64},
{"mytime": "2015-12-01T11:15:00.000Z", "value": 67},
{"mytime": "2015-12-01T11:20:00.000Z", "value": 70},
{"mytime": "2015-12-01T11:25:00.000Z", "value": 64},
{"mytime": "2015-12-01T11:30:00.000Z", "value": 72},
{"mytime": "2015-12-01T11:35:00.000Z", "value": 75},
{"mytime": "2015-12-01T11:40:00.000Z", "value": 71},
{"mytime": "2015-12-01T11:45:00.000Z", "value": 80}
];
var parseDate = d3.time.format("%Y-%m-%dT%H:%M:%S.%LZ").parse;

data.forEach(function(d) {
          d.mytime = parseDate(d.mytime);
        });
//var margin = { top: 30, right: 30, bottom: 40, left:50 },
var margin = { top: 30, right: 30, bottom: 40, left:50 },
height = 200, …
Run Code Online (Sandbox Code Playgroud)

javascript css svg d3.js

2
推荐指数
1
解决办法
1776
查看次数

使D3图表在React app中响应

我目前正在尝试使用D3在React中渲染绘图.为了整合它们,我使用了以下链接:

http://oli.me.uk/2015/09/09/d3-within-react-the-right-way/.

我还尝试了链接中提供的解决方案,使图表响应:

在d3.js中调整窗口大小时调整svg的大小

虽然它在与React集成时在独立代码中运行良好但它开始省略滴答.仅为D3工作jsfiddle:https://jsfiddle.net/adityap16/11edxrnq/1/

独立代码D3:

var data = [
{"mytime": "2015-12-01T11:10:00.000Z", "value": 64},
{"mytime": "2015-12-01T11:15:00.000Z", "value": 67},
{"mytime": "2015-12-01T11:20:00.000Z", "value": 70},
{"mytime": "2015-12-01T11:25:00.000Z", "value": 64},
{"mytime": "2015-12-01T11:30:00.000Z", "value": 72},
{"mytime": "2015-12-01T11:35:00.000Z", "value": 75},
{"mytime": "2015-12-01T11:40:00.000Z", "value": 71},
{"mytime": "2015-12-01T11:45:00.000Z", "value": 80}
];
var parseDate = d3.time.format("%Y-%m-%dT%H:%M:%S.%LZ").parse;

data.forEach(function(d) {
          d.mytime = parseDate(d.mytime);
        });
//var margin = { top: 30, right: 30, bottom: 40, left:50 },
var margin = { top: 30, right: 30, bottom: 40, left:50 }, …
Run Code Online (Sandbox Code Playgroud)

javascript svg d3.js reactjs

2
推荐指数
1
解决办法
3847
查看次数

标签 统计

d3.js ×2

javascript ×2

svg ×2

css ×1

elasticsearch ×1

groovy ×1

json ×1

python ×1

python-2.7 ×1

reactjs ×1