我是JSON的新手。我尝试使用GSON将值(在键值对中)分配为字符串数组。 JSON应如下所示:
{ "name": "path", "value": [ "/my-path" ,"/my-path2","/newpath"] }
我怎样才能做到这一点?
感谢。
答案 0 :(得分:1)
即便如此,我也不建议你使用POJOS,gson足够灵活,可以让你做你想做的事:
import asyncio
async def ping(loop, host):
p = await asyncio.create_subprocess_exec(
'ping', host, '-c', '10',
stdout=asyncio.subprocess.PIPE, loop=loop)
n = 0
while True:
n += 1
task = asyncio.Task(p.stdout.readline())
done, pending = await asyncio.wait([task], timeout=1)
if not done:
print(host, n, "==>", "Timeout!")
line = await task
if not line:
break
print(host, n, "==>", line.decode(), end="")
print(host, "==>", "done")
if __name__ == '__main__':
loop = loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)
tasks = [
# ping(loop, '8.8.8.8'),
# ping(loop, '127.0.0.1'),
ping(loop, 'example.com'),
]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()