json - 表示JSON中的矩阵

标签 json matrix

我正在尝试在JSON中使用矩阵样式数据,但它似乎不起作用。谁能帮助我了解我在做什么错?

        {
   "took": 12,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 44,
      "max_score": 1,
      "hits": [
      {
            "_index": "transactions",
            "_type": "transaction",
            "_id": "trans0007",
            "_score": 1,
            "_source": {
                "fundRelation": "[1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,1,0,1,0,0],
                                [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0],
                                [0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                                [1,0,0,1,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0],
                                [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0],
                                [0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0],
                                [0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0],
                                [0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0],
                                [1,0,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,1,1,0],
                                [1,0,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,1,1,0],
                                [1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,0,0,1,0,0],
                                [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0],
                                [0,0,1,1,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0],
                                [0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0],
                                [0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0]
                            ",
                "fundName": ["Fund A","Fund B","Fund C","Fund D","Fund E","Fund F","Fund G","Fund H","Fund I","Fund J","Fund K","Fund L","Fund M","Fund N","Fund O","Fund P","Fund Q","Fund R","Fund S","Fund T"],
                "fundColor": ["#9ACD32","#377DB8","#F5DEB3","#EE82EE","#40E0D0","#FF6347","#D8BFD8","#D2B48C","#4682B4","#00FF7F","#FFFAFA","#708090","#708090","#6A5ACD","#87CEEB","#A0522D","#FFF5EE","#2E8B57","#F4A460","#FA8072"]
            }
         }     ]
   }
}

不知道我在做什么错。

我收到以下错误消息:
> Parse error on line 19: ...    "fundRelation": "[1,0,0,1,0,0,1,0,1,
> -----------------------^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

http://jsonlint.com/

最佳答案

这里的问题是,您正在尝试将多行字符串值分配给无效的JSON的fundRelation

....
"fundRelation": "[1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,1,0,1,0,0],[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
...

或者,您可以执行以下操作:
{
    "took": 12,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 44,
        "max_score": 1,
        "hits": [
            {
                "_index": "transactions",
                "_type": "transaction",
                "_id": "trans0007",
                "_score": 1,
                "_source": {
                    "fundRelation": [
                        [1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,1,0,1,0,0],
                        [1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,1,0,1,0,0]
                    ],
                    "fundName": ["Fund A","Fund B","Fund C","Fund D","Fund E","Fund F","Fund G","Fund H","Fund I","Fund J","Fund K","Fund L","Fund M","Fund N","Fund O","Fund P","Fund Q","Fund R","Fund S","Fund T"],
                    "fundColor":["#9ACD32","#377DB8","#F5DEB3","#EE82EE","#40E0D0","#FF6347","#D8BFD8","#D2B48C","#4682B4","#00FF7F","#FFFAFA","#708090","#708090","#6A5ACD","#87CEEB","#A0522D","#FFF5EE","#2E8B57","#F4A460","#FA8072"]
                }
            }
        ]
    }
}

关于json - 表示JSON中的矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32152576/

相关文章:

python - 我想从给定的 url 中获取 json 数据,而我必须将 json 数据转换成 xml 形式

mysql - 如何在MySQL数据库中定义一个表来存储JSON对象?

python - 在Python中移动矩阵行的最快方法

php - 如果 PHP 脚本执行时间超过 53 秒,如何跳出循环

MYSQL存储过程迭代Json数组数据

php - 与 PHP 文件和本地 javascript 文件的 JSON 跨域通信

java - 计算矩阵行列式

c - MPI 矩阵乘法,进程未清理

c++ - 按第 1 列值的升序对特征矩阵列值进行排序

python - 使用来自 2 个 numpy 矩阵的数据绘制直方图