json - Cannot evaluate JSONObject.toString() android kotlin - Stack Overflow

admin2025-04-24  5

I have a json in a string form and i want to parse it with JSONObject class in kotlin. However, i get an exception when i run a test to see if the function works. Below i have an example

When i run the test i get this result

Moreover, when i debug the function i see that it cannot parse the string to json.

Why is this happening??

I have a json in a string form and i want to parse it with JSONObject class in kotlin. However, i get an exception when i run a test to see if the function works. Below i have an example

When i run the test i get this result

Moreover, when i debug the function i see that it cannot parse the string to json.

Why is this happening??

Share Improve this question asked Jan 17 at 18:22 james04james04 1,9205 gold badges26 silver badges61 bronze badges 2
  • Can you share your gradle setup too? – aafanasev Commented Jan 18 at 4:26
  • You could use a multiline string (""") in the definition of input and avoid escaping the " character. If nothing else, it will make the code more readable. – David Soroko Commented Jan 19 at 17:42
Add a comment  | 

1 Answer 1

Reset to default 0

To mock JSON, you can use Robolectric. IMport it as shown in the guide and then just run test with it: @RunWith(RobolectricTestRunner.class)

转载请注明原文地址:http://anycun.com/QandA/1745462838a90778.html