CCF Python题解(100分)201709-3 JSON查询

CCF Python题解(100分)201709-3 JSON查询

# _*_ coding=utf-8 _*_
__author__ = 'SRF'
__date__ = '2018/8/26 15:37'
# r''都不会被转义
import json

n, m = map(int, input().split())
str1 = ''
for i in range(n):
    str1 += input()
dict1 = json.loads(str1)
for j in range(m):
    keys = input().split('.')
    try:
        index = 0
        dict2 = dict1
        for index in range(len(keys)):
            if index == len(keys) - 1:
                value = dict2[keys[index]]
            else:
                dict2 = dict2[keys[index]]

        if type(value) != dict:
            print("STRING " + value)
        else:
            print("OBJECT")
    except:
        print('NOTEXIST')
        continue

猜你喜欢

转载自blog.csdn.net/qq_39577481/article/details/83988121
今日推荐