How to put JSon Objects into a python dict

问题内容:

I have a JSon object as below:

...
    "Type": ["Alpha",
    "Beta"]
...

What I want to do is loop through the object ‘Type’ and print each element out separately and store it as Type1 and Type2 in Python but cannot figure out how to.

I am doing the below:

   options={}
    for differentTypes in Types:
        if (differentTypes.key == "type"):
            options[differntTypes.key] = differentTypes.value
    print(options[0])

If I print out just options dict it prints out all the elements in the dict and if I print out the options with given element i.e. [0] it will print out first character of first type e.g., “

I do not want to have to specify the element to print out and want it to print out all different elements, and by elements I mean the whole world in this case Type1 would be Alpha and Type2 Beta.

问题评论:

原文地址:

https://stackoverflow.com/questions/47755648/how-to-put-json-objects-into-a-python-dict

Add a Comment