JSON: Difference between revisions
Content deleted Content added
added go |
|||
Line 2: | Line 2: | ||
Load a [[wp:JSON|JSON]] string into a data structure. Also create a new data structure and serialize it into JSON. |
Load a [[wp:JSON|JSON]] string into a data structure. Also create a new data structure and serialize it into JSON. |
||
Use objects and arrays, and make sure your JSON is valid (http://www.jsonlint.com/). |
Use objects and arrays, and make sure your JSON is valid (http://www.jsonlint.com/). |
||
=={{header|Go}}== |
|||
<lang go>package main |
|||
import "json" |
|||
import "fmt" |
|||
func main() { |
|||
var data map[string]interface{} |
|||
json.Unmarshal([]byte("{ \"foo\": 1, \"bar\": [10, \"apples\"] }"), &data) |
|||
fmt.Println(data) |
|||
sample := map[string]interface{}{ "blue": []interface{}{1,2}, "ocean": "water" } |
|||
json_string, err := json.Marshal(sample) |
|||
if err == nil { |
|||
fmt.Println(string(json_string)) |
|||
} else { |
|||
fmt.Println(err) |
|||
} |
|||
}</lang> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |