AdobeOA #3
Get Nested Dictionary Value by Dotted Path
估计简单可在线判题
Split the path on dots and access the dictionary one key at a time, level by level. If a key is missing or an intermediate value is not an object, return null; arrays are not accessed by index. Any JSON value found is returned as is, and null is not the string "null".
输入格式
The input has two lines: a JSON object and a JSON string path. The path is non-empty with a length of ≤200 code points, and an empty segment looks up the empty key. at most 5000 tree nodes, depth ≤30, each key and string ≤200 code points, and all keys/strings together ≤250000 code points. Values are complete JSON scalars/arrays/objects, keys are strings of Unicode scalars, and duplicate keys are invalid. Numbers are finite, each token is ≤64 characters, the absolute value of the exponent is ≤12, the absolute value is ≤10^9, and every number lies exactly on the 10^-6 grid. The total input size is ≤4MiB.
输出格式
Output one line of canonical ASCII JSON: object keys are sorted by ascending Unicode code point, with no extra whitespace; strings use ASCII JSON escapes (non-BMP characters as lowercase four-digit surrogate pairs); numbers use no exponent, trailing zeros in the fraction and a redundant decimal point are removed, and −0 becomes 0; true/false/null are lowercase. Spaces inside strings must be preserved. The unique string escaping is equivalent to Python json.dumps(value, ensure_ascii=True): printable ASCII other than the double quote and backslash is kept as is (including /), and those two are escaped with a backslash; backspace, form feed, newline, carriage return and tab use short escapes, and all other control characters as well as DEL/non-ASCII use lowercase four-digit Unicode escapes, with non-BMP characters as surrogate pairs.
样例 1
输入:
{"car":{"wheels":2,"gears":5}}
"car.gears"
输出:
5
样例 2
输入:
{"car":{"gears":5}}
"car.color"
输出:
null
样例 3
输入:
{"a":{"z":1.250000,"b":true,"n":null}}
"a"
输出:
{"b":true,"n":null,"z":1.25}
样例说明
The outputs of the three public examples are, in order: 5; null; {"b":true,"n":null,"z":1.25}. Verified by independent enumeration or direct simulation.