As I work on loading a JSON file from the database containing two fields - words and grade, I face a challenge. Each word in the file is assigned a grade, for example, "true" has a grade of 1 while "lie" has a grade of -1. My goal is to take input from a text field, grade it based on the values from the JSON file, and then calculate a score by summing up the grades. However, I am struggling to find an efficient way to achieve this. It seems that words not found in the JSON file are not being included in the calculation.
I have attempted methods like string.search() and array searches, but they proved to be too complicated and did not provide the desired results. While looking for online solutions, I realized that no one has implemented anything similar that I could emulate.
JSON
[
{"word":"true","grade":1},
{"word":"hate","grade":-1},
{"word":"dog","grade":0.8},
{"word":"cat","grade":-0.8}
]
String
"Dogs are wonderful but i prefer cats, cats, i can not lie although dog is a true friend".