-1

I am using some built in functions which is taking some arrays as input. Now I have value

String network=[{"GUID":"a","Type":"WiFi","WiFi":{"AutoConnect":true,"Passphrase":"12345678","SSID":"Free PTCL unlimited"}},{"GUID":"b","Type":"WiFi","WiFi":{"AutoConnect":true,"Passphrase":"12345678","SSID":"Free PTCL unlimited"}}]

Actually it is like an array but when i input this value the compiler say the function requires an array value. Now what i need to to convert this string into array

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
twana eng
  • 31
  • 10
  • You should start by getting a correct string, that will actually compile. – Amongalen Apr 28 '20 at 11:52
  • 2
    This is just invalid Java syntax. Java cannot parse JSON syntax directly. You need to deserialize it from a string using a JSON-parser like Jackson or Gson. – marstran Apr 28 '20 at 11:53
  • Also, if you want it to be a string, you need to add quotes (`"`). Like `String network = "...value...";`. – marstran Apr 28 '20 at 11:54
  • I think u didn't get my question – twana eng Apr 28 '20 at 11:54
  • I have an arraylist which stores values but u know due to encapsulation the function cannot read the values of arraylist so i am converting it into json using gson – twana eng Apr 28 '20 at 12:02
  • but my function needs array when i pass arraylist my function cannot read the values of arraylist to encapsulation – twana eng Apr 28 '20 at 12:02
  • as you mentioned that function need an array, not a list of array. You can simply declare and access particular element (this is a single array reside within list of array) inside list of array by index. – Harrison Chong Apr 28 '20 at 14:34

1 Answers1

0

your syntax in wrong...

when you do String network=... you declare network as a String not as an array

arrays in java must be declared/initialized like:

String[] network = {"a", "b", "c"};
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97