-
Python:
import json json_data = '{"name": "John", "age": 30, "city": "New York"}' parsed_data = json.loads(json_data) print(parsed_data["name"]) print(parsed_data["age"]) print(parsed_data["city"])
-
JavaScript:
const jsonString = '{"name": "John", "age": 30, "city": "New York"}'; const parsedData = JSON.parse(jsonString); console.log(parsedData.name); console.log(parsedData.age); console.log(parsedData.city);
-
Java:
import org.json.JSONObject; public class JSONParser { public static void main(String[] args) { String jsonString = "{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}"; JSONObject jsonObject = new JSONObject(jsonString); System.out.println(jsonObject.getString("name")); System.out.println(jsonObject.getInt("age")); System.out.println(jsonObject.getString("city")); } }
-
C#:
using System; using Newtonsoft.Json; class Program { static void Main() { string jsonString = "{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}"; dynamic jsonObject = JsonConvert.DeserializeObject(jsonString); Console.WriteLine(jsonObject.name); Console.WriteLine(jsonObject.age); Console.WriteLine(jsonObject.city); } }
在线工具:https://techtoolkit.cn/json.html