vendredi 23 juin 2017

Delete everything from an custom Object MyString except a single part plus unknow numbers

my Problem is (maybe because I am a little bit tired), that I have a custom Object called myString. It contains a line of a Json-file. Now I want to delete everything except one part of it, that contains the info that I need.

Class MyString:

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;

public class MyString {
    public String myString;

    public MyString(String myString) {
        this.myString = myString;
    }

    public Object toJson(Gson gson){
        return gson.fromJson(myString, Object.class);
    }

    public boolean nextLine(BufferedReader bufferedReader) throws IOException {
        return ((myString = bufferedReader.readLine()) != null);
    }
}

myString has some kind of this value:

[{date={year=2012.0, month=1.0, day=1.0}, time={hour=12.0, minute=0.0, second=0.0, nano=0.0}}, {date={year=2012.0, month=1.0, day=1.0}, time={hour=13.0, minute=0.0, second=0.0, nano=0.0}}, {titel=idk}, {text=pls}, {woerter=wtf}, {seconds=3600.0, nanos=0.0}]

form which I just want

{seconds=3600.0, nanos=0.0}

to

3600

Now if I use this, it does not even find "seconds=", not even speaking about those numbers:

MyString dateiInhalt = new MyString("");

//dateiInhalt gets the Line from the Json-file

Pattern regex = Pattern.compile("seconds=");
Matcher regexMatcher = regex.matcher(dateiInhalt.toString());
MyString justSeconds = new MyString(regexMatcher.group(0));

Sry for this probably really retarded question, but I am tired af and need to get this done :(

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire