-2

In Java, I have a string output like this but I have no idea about how to deal with

I mean when I WriteLine(myString) or printLn(myString)

   [["-1.816513","52.5487566"],["-1.8164913","52.548824"]]

after parsing it should be a list of string's list like below

List<List<Sring>> myList

list.get(0).get(0); should give me "-1.816513"

Any idea about how to parse this string to this list?

Ismail Sahin
  • 2,640
  • 5
  • 31
  • 58
  • 2
    what programming language are you using? Also, SO questions generally need to demonstrate the work that you've done to solve the problem yourself and any errors you're seeing, before asking for help. This will help people identify exactly what it is you're having trouble with and help you lern. – atk Aug 30 '13 at 03:44
  • Where is the problem? Your analysis for list.get(0).get(0) is also correct – Algorithmist Aug 30 '13 at 03:45

4 Answers4

2

Here is how great JavaScript and JSON work together when it comes to serializing data structures and objects.

All this available right in the JavaScript console of modern browsers:

JSON.stringify([["-1.816513","52.5487566"],["-1.8164913","52.548824"]])
"[["-1.816513","52.5487566"],["-1.8164913","52.548824"]]"
JSON.parse(JSON.stringify([["-1.816513","52.5487566"],["-1.8164913","52.548824"]]))
[
Array[2]
0: "-1.816513"
1: "52.5487566"
length: 2
__proto__: Array[0]
, 
Array[2]
0: "-1.8164913"
1: "52.548824"
length: 2
__proto__: Array[0]
stackunderflow
  • 953
  • 7
  • 17
0

you can try this:

.toString()

this can help you.. Convert array of strings into a string in Java

Community
  • 1
  • 1
Lian
  • 1,597
  • 3
  • 17
  • 30
0

I suggest to read documentation about Split method and StringTokenizer

And to transform array to List use Arrays.asList :

   Integer[] spam = new Integer[] { 1, 2, 3 };
   Arrays.asList(spam);
Charaf JRA
  • 8,249
  • 1
  • 34
  • 44
0

You can treat the

string('[["-1.816513","52.5487566"],["-1.8164913","52.548824"]]')

as the result JSONObject.toSting().

So you can find the way to convert string to JSONObject just like that:

String json="{[[\"-1.816513\",\"52.5487566\"],[\"-1.8164913\",\"52.548824\"]]}";
JSONObject jsonObj = JSONObject.fromObject(json); 

And you need import json-lib.jar and any other jars relied on.

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Daemon
  • 9