logo
down
shadow

Unable to display Json data


Unable to display Json data

By : Mohammad Mohammadi
Date : October 22 2020, 08:10 PM
To fix this issue JSON parsing is OK but you can't retrieve your data like this because you used Volley in asynchronous mode. It means that you can't assume that data will be retrieved as soon as you put the request in the queue. Maybe the queue is very long and your request can be sent later. So, when you tried to retrieve your data, you've seen that your arrayList is null, and it's normal. To deal with the asynchronous way, you have to tell Volley : "tell me when you've retrieved data". And you can do this with a listener.
Here is an example.
code :
public interface Listener {

    void onDataReceived(ArrayList<Info> list);
    void onError(int error);
}
public class BackgroundTask {
    Context context;
    ArrayList<Info> arrayList;
    Listener mListener; // listener to retrieve data
    String json_url = "http://cc97cf60.ngrok.io/api/note/";

    public BackgroundTask(Context context, Listener listener) {
        this.context = context;
        mListener = listener;
    }

    public void getArrayList() { // no return needed

        arrayList = new ArrayList<>();
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, json_url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        JSONArray jsonArray;
                        try {
                            jsonArray = response.getJSONArray("objects");
                            int i;
                            for (i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                                /*     Uri b = Uri.parse(jsonObject.getString("image")); //Type casting string to uri*/
                                String a = jsonObject.getString("title");
                                String b = jsonObject.getString("body");
                                Info info = new Info(a, b);
                                arrayList.add(info);

                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        // if listener has been set, send data
                        if (mListener != null) {
                            mListener.onDataReceived(arrayList);
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                // if listener has been set, send error
                if (mListener != null) {
                    mListener.onError(error.networkResponse.statusCode);
                }
            }
        });
        Singleton.getInstance(context).addToRequestQueue(jsonObjectRequest);
    }
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView = findViewById(R.id.recycler);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    backgroundTask = new BackgroundTask(this, new Listener() {
        @Override
        public void onDataReceived(ArrayList<Info> list) {
            thugAdapter = new ThugAdapter(list);
            recyclerView.setAdapter(thugAdapter);
        }

        @Override
        public void onError(int error) {

        }
    });
    backgroundTask.getArrayList();
}


Share : facebook icon twitter icon
Unable to display data from json.net

Unable to display data from json.net


By : Munya Munyurwa
Date : March 29 2020, 07:55 AM
Any of those help Can anyone help solve this problem, no matter what i try i cannot display the data on webpage, i can put a breakpoints at JObject o = JObject.Parse(ws); and see the data, but every attempt i have tried results in a different error.I'm trying to do is get the areaName and country. , How about something like:
code :
var weatherCity = o["search_api"]["result"][0]["areaName"][0]["value"];
unable to display json data on highcharts

unable to display json data on highcharts


By : user2242133
Date : March 29 2020, 07:55 AM
it fixes the issue I resolved this problem by using JSON.parse() function in the ui as follows:
code :
var data=output;
data=JSON.parse(data);
here I am unable to display the data that got from json parsing?

here I am unable to display the data that got from json parsing?


By : Nimax21
Date : March 29 2020, 07:55 AM
I wish this helpful for you The mistake you are doing is that you are updating UI elements in background thread. If you want to update UI element first come in main thread then update UI elements.
Try this way now
code :
class ViewController: UIViewController {

    @IBOutlet weak var navigationbar: UINavigationBar!
    @IBOutlet weak var productImage: UIImageView!
    @IBOutlet weak var productPricelbl: UILabel!
    @IBOutlet weak var productDescriptionlbl: UITextView!

    var productName :String?
    var productprice :String?
    var productdescription :String?
    var thumbnailimageArray = [String]()
    var imageArray = [String]()
    let urlString = "http://www.json-generator.com/api/json/get/cjpberBhKa?indent=2"

    override func viewDidLoad() {
        super.viewDidLoad()
        self.downloadJsonWithURL()
//        let imgURL = NSURL(string:imageArray[0])
//        if imgURL != nil {
//            let data = NSData(contentsOf: (imgURL as URL?)!)
//            self.productImage.image = UIImage(data: data! as Data)
//        }


        // Do any additional setup after loading the view, typically from a nib.
    }
    @IBAction func arrowmarkButton(_ sender: Any) {

    }
    func downloadJsonWithURL() {
        let url = NSURL(string: urlString)
        URLSession.shared.dataTask(with: (url as URL?)!, completionHandler: {(data, response, error) -> Void in
            if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary {
                print(jsonObj!.value(forKey: "Detail")!)
                if let detailsArray = jsonObj!.value(forKey: "Detail") as? NSArray {
                        if let detailDict = detailsArray[0] as? NSDictionary {
                            if let name = detailDict.value(forKey: "productName") {
                                self.productName = name as? String
                            }
                            if let thumbnailimage1 = detailDict.value(forKey: "thumnail1"){
                                self.thumbnailimageArray.append(thumbnailimage1 as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail2"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail3"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail4"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail5"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail6"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail7"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail8"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail9"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let thumbnailimage = detailDict.value(forKey: "thumnail10"){
                                self.thumbnailimageArray.append(thumbnailimage as! String)
                            }
                            if let image1 = detailDict.value(forKey: "image1"){
                                self.imageArray.append(image1 as! String)
                            }
                            if let image2 = detailDict.value(forKey: "image2"){
                                self.imageArray.append(image2 as! String)
                            }
                            if let image3 = detailDict.value(forKey: "image3"){
                                self.imageArray.append(image3 as! String)
                            }
                            if let image4 = detailDict.value(forKey: "image4"){
                                self.imageArray.append(image4 as! String)
                            }
                            if let image5 = detailDict.value(forKey: "image5"){
                                self.imageArray.append(image5 as! String)
                            }
                            if let image6 = detailDict.value(forKey: "image6"){
                                self.imageArray.append(image6 as! String)
                            }
                            if let image7 = detailDict.value(forKey: "image7"){
                                self.imageArray.append(image7 as! String)
                            }
                            if let image8 = detailDict.value(forKey: "image8"){
                                self.imageArray.append(image8 as! String)
                            }
                            if let image9 = detailDict.value(forKey: "image9"){
                                self.imageArray.append(image9 as! String)
                            }
                            if let image10 = detailDict.value(forKey: "image10"){
                                self.imageArray.append(image10 as! String)
                            }
                            if let price = detailDict.value(forKey: "productPrice") {
                                self.productprice = price as? String
                            }
                            if let description = detailDict.value(forKey: "productDes") {
                                self.productdescription = description as? String
                                print(self.productdescription)
                            }
                        }
                }
                OperationQueue.main.addOperation({
                 self.navigationbar.topItem?.title = self.productName
                 self.productDescriptionlbl.text = self.productdescription
                 self.productPricelbl.text = self.productprice
                })
            }
        }).resume()
    }
}
Unable to display data from AJAX call JSON data with jQuery

Unable to display data from AJAX call JSON data with jQuery


By : Paul Y
Date : March 29 2020, 07:55 AM
With these it helps To pass parameters to the url, you need to use the data parameter for the $.ajax() function.
From your url, it seems that the method used by the remote is GET, so this code should work :
code :
var myData = encodeURIComponent("key=YourKey&query=Support&geo=London&distance=200&tempperm=Part Time");
$.ajax({
 type: "GET",
 url: "https://www.cv-library.co.uk/search-jobs-json",
 data = myData,
 success: function(data)
 {
    console.log(data);

    $.each(data.results, function(i, val) {
        // here you can do your magic
        $("#joblist").append(document.createTextNode(val.title));
        $("#joblist").append(document.createTextNode(val.logo));
    });
 }

});
$.each(data.jobs, function(i, val) {
    $("#joblist").append(document.createTextNode(val.agency.title));
    $("#joblist").append(document.createTextNode(val.logo));
});
unable to display json data on ejs template

unable to display json data on ejs template


By : user2279030
Date : March 29 2020, 07:55 AM
Hope that helps I am trying to showing json data in ejs template but i am failed. my json data format is- , use ForEach try this code
code :
<% result.faq.forEach( function (element) { %> 
                 <%= element.name %>  
                 <%= element.ans %>  
                 <%= element.link %>  
  <% }); %>
Related Posts Related Posts :
  • Interrupt CompletableFuture with default value
  • Eclipse - Choosing servers in "Run on server" vs setting "Target Runtime"
  • Spring JPA doesn't validate bean on update
  • How is takeWhile different from filter?
  • Spring Scheduled Cron jobs firing at wrong time
  • JFrame window resizing on every compile. Different results every time
  • Kotlin unresolved reference :add after converting from Java code
  • How to use Neo4j APOC method " apoc.export.csv.query(query,file,config)" in Java program
  • Regex to include all spanish characters and number
  • Parsing and Mapping a JSON Object with Dynamic Properties
  • Which approach to building domain objects in Spring MVC is more correct?
  • Java Long Min and Max not exact as mentioned in docs
  • Selenium opens new tab after SendKeys
  • How to sort a large array of ints?
  • FitNessse Test can not find Fixture
  • Including Signed Libraries in Executable JAR with Maven
  • If and Else statement run on second iteration of while loop
  • Change class of disabled tab on change of dropdown value
  • Junit5 @ParameterizedTest How to pass array as one of parameter
  • Text message not being sent to a list of numbers but is sent when just one number is specified
  • Spring mapped servlet not called in jetty-maven-plugin
  • How to pace the consumption of a sqs queue using spring integration
  • Autowiring Not getting disabled using xml configuration
  • Maze solve and shortest path with Java BFS
  • Spinner updating only on user actions
  • Why are Java rules for protected access such as they are?
  • Modify parameter of method by value in annotation aspectJ
  • How to send sensitive data to a Liferay portlet from outside the Liferay portal
  • Does a server connection stay open if created inside a method?
  • JAR manifest Class-Path, use folder instead of jar
  • How to do a bulk update in Firestore
  • ItemArray.checklist.add() not appending string to ArrayList
  • How to move something on screen without other picture staying there
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org