Skip to content

Latest commit

 

History

History

001-how-to-use-json-in-javascript

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
title c3p hasDemo deprecated preview tags date
How to use JSON in JavaScript
how-to-use-json-in-javascript-20.05.26.c3p
true
true
preview.png
javascript
created updated
2020-05-27 12:00
2020-05-27 12:00
<script> const isSvelte = (window.location.href.substring(window.location.href.length - 9)) !== "readme.md"; </script>

{#if !isSvelte}

How to use JSON in JavaScript

{/if}

global_runtime.js

runOnStartup(async  runtime =>  {  globalThis.g_runtime  =  runtime })

json_helper.js

let json = null;
let jsonObj = null;

function json_initialize(json_name) {
	json = g_runtime.objects[json_name].getFirstInstance();
	jsonObj = json.getJsonDataCopy();
}

function json_getKey(json_key){
	const result = jsonObj[json_key];
	return JSON.stringify(result);
}

function json_changeKey(key, value) {
	jsonObj[key] = value
	json.setJsonDataCopy(jsonObj);
}

Event Sheet

screenshot