0

I need help to fetch JSON from RESTfull API.

This is my Response

"variation_details": [
    {
        "variation_title": "Black Color",
        "specifications": "Diamond Cut",
        "image": [
            "/uploads/variation-img0-0-Redmi J812127868.jpg"
        ],
        "quantity": 10,
        "price": 20000
    }
],

how can i remove [] this. from response because i need to display image in view Pager

This is how i get From response http://devapi.dicatto.com[/uploads/variation-img0-0-Redmi J812127868.jpg]

this is my full response

{
    "code": true,
    "success": "Records fetched successfully",
    "result": {
        "name": "Redmi J812127868",
        "main_category": "5cde6e836340c5659e5c6992",
        "sub_category": "5cde6f199aed456592c98f98",
        "brand": "5cdeab466340c5659e5c69bd",
        "model": "PROD771100",
        "currency": "Rs",
        "mrp_price": 18000,
        "retailer_price": 17000,
        "quantity": 30,
        "available_quantity": null,
        "avg_ratings": null,
        "description": null,
        "performance": null,
        "other_infomation": null,
        "product_description": "Test1234",
        "specifications": "<p>RAM-4&nbsp;</p>\n",
        "features": [
            {
                "title": "RAM:4 GB,Memory:64 GB",
                "description": "Test",
                "image": "/uploads/feature-img0-Redmi J812127868.jpg"
            }
        ],
        "warranty": "12 Months",
        "replacement": "Screen",
        "same_day_delivery": null,
        "discounted_amount": 2000,
        "cash_on_delivery": null,
        "manufacturing_details": "Test1232",
        "importer_details": "Mumbai Test1232",
        "packers_details": "Test123",
        "offers": null,
        "highlights": "Mumbai",
        "more_info": null,
        "keywords": null,
        "manufacturer": null,
        "variation_theme": "color",
        "variation_details": [
            {
                "variation_title": "Black Color",
                "specifications": "Diamond Cut",
                "image": [
                    "/uploads/variation-img0-0-Redmi J812127868.jpg"
                ],
                "quantity": 10,
                "price": 20000
            }
        ],
        
        
        "__v": 0
    }
}

The response change when multiple image come

"variation_details": [
    {
        "variation_title": "Black Color",
        "specifications": "Diamond Cut",
        "image": [
            "/uploads/variation-img0-0-Redmi J812127868.jpg",
            "/uploads/variation-img0-1-Redmi J812127868.jpg"
        ],
        "quantity": 10,
        "price": 20000
    }
],
7
  • [] represent list of items. So if you dont need list then just define one instance of details/image. Commented Jun 4, 2019 at 6:26
  • bro it come list in array in this key image can you show some snippet to remove this [] Commented Jun 4, 2019 at 6:29
  • you don't want image key in you json correct? Commented Jun 4, 2019 at 6:30
  • tranform your input to output by changing array/list by taking just '0'th index item (assuming you would always get one item of image/variation details.) Commented Jun 4, 2019 at 6:32
  • @Vishalkumarsinghvi no i need image Key to fetch from API Commented Jun 4, 2019 at 6:32

2 Answers 2

2

Variation_details.java

public class Variation_details
{
    private String[] image;

    private String quantity;

    private String price;

    private String specifications;

    private String variation_title;

    public String[] getImage ()
    {
        return image;
    }

    public void setImage (String[] image)
    {
        this.image = image;
    }

    public String getQuantity ()
    {
        return quantity;
    }

    public void setQuantity (String quantity)
    {
        this.quantity = quantity;
    }

    public String getPrice ()
    {
        return price;
    }

    public void setPrice (String price)
    {
        this.price = price;
    }

    public String getSpecifications ()
    {
        return specifications;
    }

    public void setSpecifications (String specifications)
    {
        this.specifications = specifications;
    }

    public String getVariation_title ()
    {
        return variation_title;
    }

    public void setVariation_title (String variation_title)
    {
        this.variation_title = variation_title;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [image = "+image+", quantity = "+quantity+", price = "+price+", specifications = "+specifications+", variation_title = "+variation_title+"]";
    }
}

Variation_details.getImage()[0]; you can fetch image key

Sign up to request clarification or add additional context in comments.

11 Comments

check syntax may be some problem logic you can find above.
Thanks bro i get response finally but in that image key if it comes list["",""] like this its show in list..??
you mean to say that multiple images
you want to display all image in somewhere
use for loop and store in arraylist and display now i am done for this problem keep trying .
|
0

Use Pojo to Get Response data easily.

With Pojo You can get All YOur response data correctly and with easy method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.