Stefan M.
2 min readFeb 3, 2016

--

{
"name" : "Stefan",
"age" : 24,
"location" : "Top Secret",
"nickname" : "StefMa"
}
public class Main {

public Main() {
Gson gson = new Gson();
Human human = gson.fromJson(jsonString, Human.class);
}

}
public class Human {

@SerializedName("name")
public String mName;

@SerializedName("age")
public int mAge;

@SerializedName("location")
public String mLocation;

@SerializedName("nickname")
public String mNickname;

}
from human import human
import json

json_string = '{"name" : "Stefan", "age" : 24, "location" : "Top Secret", "nickname" : "StefMa"}'

human_object = json.loads(json_string, object_hook=human.createHuman)
class human():
def __init__(self):
self.name = ""
self.age = 0
self.location = ""
self.nickname = ""

@staticmethod
def createHuman(json_dict):
h = human()
h.name = json_dict["name"]
h.age = json_dict["age"]
h.location = json_dict["location"]
h.nickname = json_dict["nickname"]
return h

--

--