javascript deserialize json code example
Example 1: javascript parse json
var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
Example 2: javascript json deserialize
var objData = JSON.parse(json_string);
Example 3: java deserialize json
private Car parseCar(JsonNode node) {
Car car;
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule().addDeserializer(Car.class, new CarDeserializer());
mapper.registerModule(module);
organization = mapper.convertValue(node, Car.class);
return car;
}
//deserializer class
public class CarDeserializer extends StdDeserializer<Car> {
public CarDeserializer() {
super(Car.class);
}
@Override
public Car deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JodaModule());
Car car = new Car();
car.setName(getValueAsText(root, "carName"));
car.setDoorCount(getValueAsInt(root,"doorCount"));
car.setColor(getValueAsText(root,"color"));
car.setType(getValueAsText(root,"type"));
return car;
}
}
Example 4: deserialize json jquery
const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);