1. Engineering
2. Computer Science
3. java code problem level introduction to java write a method...

# Question: java code problem level introduction to java write a method...

###### Question details

java code problem

level: introduction to java

Write a method as shown below:

protected String extractValue (int index, String jsonObject)

This method takes in the index of the ending quotation mark of a key (before the colon) in the jsonObject and returns the value (after the colon) for that key as a String. Make sure to check if the input index is a valid index. If it is an invalid index, return null.

For example, given the jsonObject below:

{"some_other_key": -1.4, "the_key_we_want": "some value"}
• If index pointed to the ending quotation mark around "some_other_key", you would return the String -1.4
• If index pointed to the ending quotation mark around "the_key_we_want", you would return the String some value

Reminder: There shouldn't be any whitespace or any other trailing characters (like quotation marks or colon) at the ends of value.

Hints: 1. find the index of ":" which is nearest to the input index. And the index of the ":" should come after the input index

2. Record everything that comes after that until you hit "," or "}".

3. return whatever you have recorded

4. If the input jsonObject is {"the_key_we_want":    10}

5. JSON object library should not be used. Treat the @param jsonObject as a normal string.

the output will be "10" without extra space.