2016-07-29 58 views
0

我Json的輸入,可以是兩種形式確定文件是否JSON記錄或單個JSON記錄的名單

JSON記錄
  1. 列表:取樣記錄{"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}

有可能是在由新的行字符分隔的文件中n個這樣的記錄。

  • 文件本身是一個記錄:取樣記錄:{ "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 } }
  • 是否有在它們之間確定任何可能的方式。

    回答

    0

    除非您閱讀,否則無法確定文件中的內容。

    我認爲你真的需要讀取所有文件..解析它的數據來確定它是否是一個列表。^_^

    +0

    我明白它不能在沒有讀取文件的情況下實現。你可以請一些片段的幫助 –