确定文件是JSON记录列表还是单个JSON记录

时间:2016-07-29 05:46:14

标签: json file

我有Json输入,可以有两种形式

  1. JSON记录列表:示例记录{"l7ProtocolID":"dhcp","packets_out":1,"bytes_out":400,"start_time":1454281199898,"flow_sample":0,"duration":102,"path":["base","ip","udp","dhcp"],"bytes_in":1200,"l4":[{"client":"68","server":"67","level":0}],"l2":[{"client":"52:54:00:50:04:B2","server":"FF:FF:FF:FF:FF:FF","level":0}],"l3":[{"client":"::ffff:0.0.0.0","server":"::ffff:255.255.255.255","level":0}],"flow_id":"81454281200000731489","applicationID":"dhcp","packets_in":1}
  2. 在新行字符分隔的文件中可能有n条此类记录。

    1. 文件本身是一条记录:样本记录:{ "status": "ok", "response": { "submissions": [ { "id": "59434767", "timestamp": "2011-11-21 09:21:53", "user_agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0", "remote_addr": "192.168.1.1", "payment_status": "", "data": [ { "field": "13776121", "value": "Baylor Dallas" }, { "field": "13776401", "value": "CHF" }, { "field": "13777966", "value": "John Doe" }, { "field": "13780027", "value": "9999" }, { "field": "13778165", "value": "None of the above" }, { "field": "13778985", "value": "Yes" }, { "field": "13778280", "value": "Yes" }, { "field": "13778424", "value": "Yes" }, { "field": "13778290", "value": "Yes" }, { "field": "13778324", "value": "Yes" }, { "field": "13778864", "value": "Yes" } ] }, { "id": "59474875", "timestamp": "2011-11-21 17:01:22", "user_agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0", "remote_addr": "192.168.1.1", "payment_status": "", "data": [ { "field": "13776121", "value": "Healthsouth," }, { "field": "13776401", "value": "Pneumonia" }, { "field": "13777966", "value": "Jane Doe" }, { "field": "13780027", "value": "390" }, { "field": "13778165", "value": "Experienced a fall?" }, { "field": "13861153", "value": "Yes" }, { "field": "13780018", "value": "Yes" }, { "field": "13780006", "value": "No" }, { "field": "13780023", "value": "Yes" }, { "field": "13780024", "value": "Yes" } ] } ], "total": 2, "pages": 1 } }
    2. 是否有任何可能的方法来识别它们。

1 个答案:

答案 0 :(得分:0)

除非您阅读,否则您无法确定文件中的内容。

我认为你真的需要阅读所有文件..解析它的数据以确定它是否是一个列表。 ^ _ ^