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 Answers
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.

- 554
- 1
- 7
- 23
1.You can base64 image encoding use to it.
{ "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" }

- 93
- 10
There are two option for adding image in the JSON :
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.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
}

- 662
- 1
- 6
- 17