Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Correcting strings inside json file

I have a json file in that title entity is there. I parse the title, it gives error because of '\' character in the title.

for(int i = 0; i < stringJSON.length() - 1; i++){
                if(stringJSON.charAt(i) == character && !(stringJSON.charAt(i+1) == character)){
                    rawJSON = new StringBuilder(stringJSON).insert(i+1, '\\').toString();
                    i = i + 2;
                   System.out.println("found at " + i);
                }

Input json file is as below-

{ "class":
        {
            "number": 2,
            "student": 
            {
            "title": "\\The first day \b of my life",
            "age": 1
            },
            "student": 
            {
            "title": "\\A corner in the \A home",
            "age": 2
            }
        }
    }  

The solution above have lot of issues, like "\\" is a valid character, '\"' is a valid character.

Can somebody help me to find out any java package or API which helps to auto correct this kind of error?

In the second record of student, you can see a single slash. That makes json invalid.

My question is how to correct this json? I can either remove it or append one more slash to make it valid json string.

The string is combination of escape characters "\\", and control character '\'.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This answers what you are asking:

You can see there how the \ is a "control" character. If you want a literal backslash within your JSON, you'll need to escape it: "\\" is a valid JSON string, for example.

Source: JSON Valid Chars

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda