#Program -1, To print array of array
a = [[{'Key': 'key700', 'Value': 'val145'}, {'Key': 'key123', 'Value': 'val123'}]]
for i in range(len(a)):
for j in range(len(a[i])):
jsonData = a[i][j]
#print(jsonData);
for (k, v) in jsonData.items():
print("Key: " + k)
print("Value: " + str(v))
'''
output
********
Key: Key
Value: key700
Key: Value
Value: val145
Key: Key
Value: Key123
Key: Value
Value: val123
'''
#Program -2 , print only the key=userName
import json
a = [[{'Key': 'age', 'Value': '10'}, {'Key': 'userName', 'Value': 'vijay'}, {'Key': 'address', 'Value': '1, car st'}, {'Key': 'userName', 'Value': 'pranika'}]]
for i in range(len(a)):
for j in range(len(a[i])):
jsonData = a[i][j]
data = json.loads(json.dumps(jsonData ) );
if ( jsonData['Key'] == 'Name' ):
print ( jsonData['Value'] )
'''
output
********
vijay
pranika
'''
a = [[{'Key': 'key700', 'Value': 'val145'}, {'Key': 'key123', 'Value': 'val123'}]]
for i in range(len(a)):
for j in range(len(a[i])):
jsonData = a[i][j]
#print(jsonData);
for (k, v) in jsonData.items():
print("Key: " + k)
print("Value: " + str(v))
'''
output
********
Key: Key
Value: key700
Key: Value
Value: val145
Key: Key
Value: Key123
Key: Value
Value: val123
'''
#Program -2 , print only the key=userName
import json
a = [[{'Key': 'age', 'Value': '10'}, {'Key': 'userName', 'Value': 'vijay'}, {'Key': 'address', 'Value': '1, car st'}, {'Key': 'userName', 'Value': 'pranika'}]]
for i in range(len(a)):
for j in range(len(a[i])):
jsonData = a[i][j]
data = json.loads(json.dumps(jsonData ) );
if ( jsonData['Key'] == 'Name' ):
print ( jsonData['Value'] )
'''
output
********
vijay
pranika
'''
No comments:
Post a Comment