JsonToDictionaries

Published on January 11, 2022

🏷️ Tags: #kodular, #json, #extensions

A non-visible extension that turns JSON text into Dictionary blocks. This extension is only usable in Kodular, where this block does not exist in the Web component.

Made with Niotron IDE at https://ide.niotron.com.

Current version: 1 Package name: com.gordonlu.jsontodictionaries.aix

πŸ“– Documentation

Method blocks

JsonTextDecodeWithDictionaries - Decodes the JSON text into Dictionary blocks or an App Inventor value.

Open Source

package com.gordonlu.jsontodictionaries;


import android.app.Activity;

import android.content.Context;

import com.google.appinventor.components.annotations.*;

import com.google.appinventor.components.common.ComponentCategory;

import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;

import com.google.appinventor.components.runtime.ComponentContainer;

import com.google.appinventor.components.runtime.EventDispatcher;


import androidx.annotation.VisibleForTesting;


import com.google.appinventor.components.runtime.errors.IllegalArgumentError;

import com.google.appinventor.components.runtime.errors.PermissionException;

import com.google.appinventor.components.runtime.errors.RequestTimeoutException;

import com.google.appinventor.components.runtime.repackaged.org.json.XML;

import com.google.appinventor.components.runtime.util.AsynchUtil;

import com.google.appinventor.components.runtime.util.BulkPermissionRequest;

import com.google.appinventor.components.runtime.util.ErrorMessages;

import com.google.appinventor.components.runtime.util.FileUtil;

import com.google.appinventor.components.runtime.util.GingerbreadUtil;

import com.google.appinventor.components.runtime.util.JsonUtil;

import com.google.appinventor.components.runtime.util.MediaUtil;

import com.google.appinventor.components.runtime.util.SdkLevel;

import com.google.appinventor.components.runtime.util.XmlParser;

import com.google.appinventor.components.runtime.util.YailDictionary;

import com.google.appinventor.components.runtime.util.YailList;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.StringReader;

import java.io.UnsupportedEncodingException;


import java.net.CookieHandler;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.ProtocolException;

import java.net.SocketTimeoutException;

import java.net.URISyntaxException;

import java.net.URL;

import java.net.URLDecoder;

import java.net.URLEncoder;

import java.util.List;

import java.util.Map;


import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;


import org.json.JSONException;


import org.xml.sax.InputSource;


@DesignerComponent(

version = 1,

description = "An extension that converts JSON text to dictionary blocks. This extension is only usable in Kodular, where this block does not exist in the Web component.",

category = ComponentCategory.EXTENSION,

nonVisible = true,

iconName = "https://docs.google.com/drawings/d/e/2PACX-1vQCI87PHLBF0jb8QWyYmIRQSjjNW3EFXf-qpsWCvBYkUQ9vEgPAB8SpxcMpblxNpbIYrjCjLrRLIU2c/pub?w=16&h=16")


@SimpleObject(external = true)

//Libraries

@UsesLibraries(libraries = "")

//Permissions

@UsesPermissions(permissionNames = "android.permission.READ_EXTERNAL_STORAGE")


public class JsonToDictionaries extends AndroidNonvisibleComponent {


//Activity and Context

private Context context;

private Activity activity;


public JsonToDictionaries(ComponentContainer container){

super(container.$form());

this.activity = container.$context();

this.context = container.$context();

}


@SimpleFunction (description = "Decodes the JSON text into Dictionary blocks.")

public Object JsonTextDecodeWithDictionaries(String jsonText) {

try {

return decodeJsonText(jsonText, true);

} catch (IllegalArgumentException e) {

form.dispatchErrorOccurredEvent(this, "JsonTextDecodeWithDictionaries",

ErrorMessages.ERROR_WEB_JSON_TEXT_DECODE_FAILED, jsonText);

return "";

}

}


@VisibleForTesting

static Object decodeJsonText(String jsonText, boolean useDicts) throws IllegalArgumentException {

try {

return JsonUtil.getObjectFromJson(jsonText, useDicts);

} catch (JSONException e) {

throw new IllegalArgumentException("jsonText is not a legal JSON value");

}

}


@Deprecated

@VisibleForTesting

static Object decodeJsonText(String jsonText) throws IllegalArgumentException {

return decodeJsonText(jsonText, false);

}

}

TERMS AND CONDITIONS

By downloading or sharing my extension, you agree to follow these terms and conditions.

  1. Have fun using the extension!

  2. This is the only authorized place to download this extension. As an organization, you are not allowed to host and advertize this extension on your website, document, tweet, blog, article or any software you made without my authorization. You are also reminded not to include a direct download link of this extension on your website without my permission. If you are interested in the actions listed above, please contact me via email. Do remember that if you violate term no. 2, AICODE has the right to flag your website, document, tweet, blog or article as a violation of copyright, or other legal actions will be taken. Please contact me if you find anyone do this.

However, you can copy the link of this webpage and share it to someone as a personal identity (not as an organization), or sharing it on these authorized forums: App Inventor, Kodular, Niotron, Appzard and Android Builder communities. The term organization includes schools, markets and app stores, companies and social groups. Thank you for your understanding.

Those organizations are authorized to advertize or host my extension:

  • Kodular admins

  • MIT App Inventor admins

  • Pura Vida Apps / Taifun Baer

  1. Selling this extension/product to anyone is not allowed unless authorized by AICODE.

  2. These terms and conditions are written and issued on December 20, 2021. AICODE has the total permission to edit these terms and conditions anytime.

πŸ’¬ Messages

βš™οΈ πŸ”’ CLOSED 02.20.2022 - This extension will no longer receive any updates.