|
发表于 2022-8-12 23:41:41
|
显示全部楼层
答案应该是C吧:2 t# w( O1 h( }2 f% `$ b* L
import json/ l3 p, p% d4 [0 D7 s: r
) v* X6 J* e, u3 ~+ q
response = """
6 ?4 A8 c1 P* [7 w! ~. f s{
0 O0 d% H2 R! @0 p" c+ q) W" |6 ~ "response":[{7 n, M1 v1 u) r/ X7 i# T* J5 o
"family": "Switches",, Y) g* @$ S5 P- |+ ?
"macAddress": "00:41:49:45:76:00",& N/ p3 o: j) X, ^% d. o
"hostname": "SwitchIDF14",
5 g+ Q# Z' |% C3 J2 p7 H4 C3 R "upTime": "352 days, 6:17:26:10",
4 k* L) h& k z; e$ ?5 R" G "lastUpdated": "2020-07-12 21:15:29". p" o% C6 I/ w& ^. [+ N
}]
; Y) q, r8 v! `! k}
. u. R5 X7 ~! i# Z7 g"""& C& c! t/ {7 c7 k# S& M* u
json_data = json.loads(response)
, e$ s& h+ s: K! n1 l9 M6 G) A- tprint(json_data['response'][0]['hostname']): a' L- g$ E" b) n
7 S4 ^* ?- A0 n: w/ d5 @& [- M
运行结果:
5 a9 G; \8 E4 a3 N6 k. kc:\Test\temp\json>python test_json.py, |+ l& k7 b2 N+ f) q2 M2 J
SwitchIDF14
9 Q/ c/ g4 a1 D" @% O' L x( D7 R1 W+ m4 _
c:\Test\temp\json> |
6#
2022-8-12 23:41:41
回复(0)
收起回复
|