0

please how can I add image to this question. it is written in JSON array. { "question": "Nigeria National flag color is?", "choice1": "Red Black and Gold", "choice2": "Yellow Gold and Yellow", "choice3": "Purple Red and Pink", "choice4": "Green White and Green", "answer": 4 }

3 Answers3

0

First, convert the image to byte array then add that byte as a JSON value in a JSON key.

example.

Image -> byte array

JSON

{
  //... rest of the keys and value 
  "image": "byte array here"  
}

NOTE:

1. if your images are of large size i.e. more than 1MB then use object host(AWS service or other cloud services).

2. Only use the above solution for less than 500KB images.

Hasan Khan
  • 554
  • 1
  • 7
  • 23
0

1.You can base64 image encoding use to it.

https://www.base64encode.org/

{ "question": "Nigeria National flag color is?", "choice1": "Red Black and Gold", "choice2": "Yellow Gold and Yellow", "choice3": "Purple Red and Pink", "choice4": "Green White and Green", "answer": 4 , "image": "base6encodeing" }

In javascript: Convert image from url to Base64

In c# Convert an image (selected by path) to base64 string

2. Image url use in json.

{ "question": "Nigeria National flag color is?", "choice1": "Red Black and Gold", "choice2": "Yellow Gold and Yellow", "choice3": "Purple Red and Pink", "choice4": "Green White and Green", "answer": 4 , "image": "http:\\mydomain.com\img\upload.jpeg" }
onoffon
  • 93
  • 10
0

There are two option for adding image in the JSON :

  1. You can upload your image to the server and get a server link for image, add path to the JSON and then you can show your image to the corresponding view.

  2. You can get directory path for a particular image and add path to the JSON

in both ways JSON will look like this :

{
  "question": "https://via.placeholder.com/300.png/09f/fff",
  "choice1": "Red Black and Gold",
  "choice2": "Yellow Gold and Yellow",
  "choice3": "Purple Red and Pink",
  "choice4": "Green White and Green",
  "answer": 4
}
Kishan Mevada
  • 662
  • 1
  • 6
  • 17