How to create this type of block of json utils

But, I got an error from using this code

Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml

extensions:

clean:

init:

common_CommonUtils:

init:

CommonUtils:

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

CopyToRunLibDir:

components_AndroidRuntime:

init:

CommonConstants:
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants/com/google/appinventor/components/common/package-info.class
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants.jar
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants-gwt.jar

HtmlEntities:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/components/build/HtmlEntities.jar

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

AndroidRuntime:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/chand_nami_2000/Request/Request.java:38: error: package com.google.appinventor.components.runtime.repackaged.org.json does not exist
[javac] [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/chand_nami_2000/Request/Request.java:38: error: package com.google.appi [javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with [javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 7 seconds

@Nami_Chand please post your code here let me look

/** ~~~~~

  • Created with the AppyBuilder Code Editor.
  • This is a template for basic Extension.
  • Modify this template to customize your extension.
  • **** NOTE: DO NOT use a package name.
  • **** The package name will be created for you automatically.
  • **** Adding a package name will cause a compile error
    */
    import android.app.Activity;
    import com.google.appinventor.components.annotations.DesignerComponent;
    import com.google.appinventor.components.annotations.SimpleEvent;
    import com.google.appinventor.components.annotations.SimpleFunction;
    import com.google.appinventor.components.annotations.SimpleObject;
    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 com.google.appinventor.components.runtime.util.AsynchUtil;

import java.util.Iterator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

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

import org.json.*;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

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

@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
description = ā€œMade my YOUā€,
nonVisible = true,
iconName = ā€œICON LINKā€)

@SimpleObject(external = true)

public class Request extends AndroidNonvisibleComponent {

private Activity activity;

public Request(ComponentContainer container) {
    super(container.$form());
    activity = container.$context();
}

@SimpleFunction()
public Object GetValue(String object,String key){
try {
org.json.JSONObject jsonObject = new org.json.JSONObject(object);
return jsonObject.get(key);
}catch (Exception e){
e.printStackTrace();
}
return ā€œā€;
}

}

@Nami_Chand it should be jsonObject.getString(key); ;

:roll_eyes:

1 Like

I got an error from using this newly code

Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml

extensions:

clean:

init:

common_CommonUtils:

init:

CommonUtils:

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

CopyToRunLibDir:

components_AndroidRuntime:

init:

CommonConstants:
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants/com/google/appinventor/components/common/package-info.class
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants.jar
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants-gwt.jar

HtmlEntities:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

AndroidRuntime:
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/chand_nami_2000/Request/Request.java:38: error: package com.google.appinventor.components.runtime.repackaged.org.json does not exist
[javac] import com.google.appinventor.components.runtime.repackaged.org.json.JSONObject;
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 6 seconds
^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 7 seconds

Remove the imported package that i have said and then again build it

Woo hoo! Its success. Build successful.

1 Like

I am trying this extension.

How we set permanent key in this code.

I didnā€™t understand you
Do you want to get the value of a particular key??

Sorry i want set permanent object in this code.

Hence you donā€™t need to take the object parameter from the user and replace the object string with your JSON object

how please write the code.

Just remove the object param from your function like this

@SimpleFunction
public Object GetValue(String key){
     String object="your json here";
    JSONObject object=new JSONObject(object);
    return object.getString(key);
}  

If you also want to use permanent key then do the same by removing the key param and after specify it in your function same like object

1 Like

Where do you get the sample code?
tell me for learn.

From my mindā€‹:joy:
Itā€™s my own code if you want to learn then just google about json in java and you will get all the info about JSON

Or more here

https://www.tutorialspoint.com/json/json_java_example.htm

1 Like

But these code are different from your codes.
Tell me how to convert.

Bharat mata ki jai.

If you ask me then thats not how coding in any language works
you forst need to understand the stuff that you are doing in this case Json
So you first have to understands for Json objects work and some basic java stuff

If you just copy/paste stuff then there is no type of learning in it.
And programming isnā€™t just copy pasting!

Hope this helps
I am not trying to be rude :slight_smile:

But there are no more tutorial on youtube for learn.

Did you saw sumitā€™s reply?

Google Says:

There are more than 57,300,000 webpages related :smiley: