Wenn Sie die JSON-Analyse nicht verstehen, lesen Sie bitte den Artikel hier.
** [Swift5] Verwenden Sie library'SwiftyJSON, um Array- (individuelle) Informationen von JSON abzurufen ** https://qiita.com/nkekisasa222/items/84c40bbfacfaca9f38a9
joyCountArray.
[{
"document_tone" : {
"tones" : [
{
"tone_name" : "Joy",
"score" : 0.53749899999999995,
"tone_id" : "joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
]
},
"sentences_tone" : [
{
"tones" : [
],
"text" : "Kozai \"Aza\" Haruka: Haruka, Ie no Haruka: Haruka, Ie no Haruka, 'The body is too clean.'",
"sentence_id" : 0
},
{
"tones" : [
],
"text" : "(Entame NEXT)",
"sentence_id" : 1
}
]
}, {
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"score" : 0.67608400000000002,
"tone_name" : "Joy"
},
{
"tone_id" : "analytical",
"score" : 0.92818699999999998,
"tone_name" : "Analytical"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Joy",
"score" : 0.74235700000000004,
"tone_id" : "joy"
}
]
},
"sentences_tone" : [
{
"sentence_id" : 0,
"tones" : [
],
"text" : "Ariyoshi is also a lavatory?"
},
{
"sentence_id" : 1,
"tones" : [
{
"tone_name" : "Joy",
"tone_id" : "joy",
"score" : 0.75596300000000005
}
],
"text" : "Mihopa's \"overwhelmable beauty Body\" sexy water shoe shots are released (Entame NEXT)"
}
]
}, {
"sentences_tone" : [
{
"text" : "Yuzuno Mizusawa, a beautiful woman with a hairstyle of blue hair, is released from hair color to a single one-peoped kamiwanpi with a blue-leg.",
"sentence_id" : 0,
"tones" : [
{
"tone_id" : "joy",
"tone_name" : "Joy",
"score" : 0.76069399999999998
}
]
},
{
"sentence_id" : 1,
"text" : "(Entame NEXT)",
"tones" : [
]
}
],
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"score" : 0.76504700000000003,
"tone_name" : "Joy"
}
]
}
}, {
"sentences_tone" : [
{
"text" : "Princess Inster of the Graviar world, Inster Saki Saki, said, \"I may not have felt any resistance to escaping from the beginning.\"",
"sentence_id" : 0,
"tones" : [
{
"tone_id" : "joy",
"score" : 0.64593199999999995,
"tone_name" : "Joy"
},
{
"tone_id" : "tentative",
"score" : 0.86333300000000002,
"tone_name" : "Tentative"
}
]
},
{
"text" : "(Entame NEXT)",
"sentence_id" : 1,
"tones" : [
]
}
],
"document_tone" : {
"tones" : [
{
"score" : 0.65832100000000005,
"tone_name" : "Joy",
"tone_id" : "joy"
},
{
"score" : 0.98048800000000003,
"tone_name" : "Tentative",
"tone_id" : "tentative"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"score" : 0.70347899999999997,
"tone_name" : "Joy",
"tone_id" : "joy"
}
]
}
}, {
"sentences_tone" : [
{
"sentence_id" : 0,
"text" : "\"Shiratama\" in \"The Edge of the Bend\" and the dog dog \"Shiratama\" (The Dog Warrior), a dog in the Twin Till, the dog of the Twin Tin.",
"tones" : [
]
},
{
"sentence_id" : 1,
"text" : "(Entame Next)",
"tones" : [
]
}
],
"document_tone" : {
"tones" : [
]
}
}, {
"document_tone" : {
"tones" : [
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Analytical",
"score" : 0.61642600000000003,
"tone_id" : "analytical"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"score" : 0.58929500000000001,
"tone_id" : "analytical",
"tone_name" : "Analytical"
}
]
}
}, {
"sentences_tone" : [
{
"text" : "Perfume, grag, grag, chalen, grag, grag!",
"sentence_id" : 0,
"tones" : [
]
},
{
"text" : "The two shots that were too beautiful were the subject of the buzzo (Entame Next).",
"sentence_id" : 1,
"tones" : [
{
"tone_name" : "Joy",
"score" : 0.80030299999999999,
"tone_id" : "joy"
}
]
}
],
"document_tone" : {
"tones" : [
{
"tone_name" : "Joy",
"score" : 0.79371400000000003,
"tone_id" : "joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"score" : 0.63750700000000005,
"tone_name" : "Joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Joy",
"score" : 0.83795299999999995,
"tone_id" : "joy"
}
]
}
}, {
"sentences_tone" : [
{
"sentence_id" : 0,
"tones" : [
{
"tone_name" : "Joy",
"tone_id" : "joy",
"score" : 0.67072399999999999
}
],
"text" : "\"Bomb Girl,\" \"Bomb Girl,\" with a limited number of New Hare Acaler in the public, \"It's getting more and more cute.\""
},
{
"sentence_id" : 1,
"tones" : [
],
"text" : "(Entame NEXT)"
}
],
"document_tone" : {
"tones" : [
{
"score" : 0.69078499999999998,
"tone_id" : "joy",
"tone_name" : "Joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
]
}
}, {
"sentences_tone" : [
{
"sentence_id" : 0,
"tones" : [
{
"tone_id" : "tentative",
"tone_name" : "Tentative",
"score" : 0.71630099999999997
}
],
"text" : "\"I'm happy just looking at the scene of the popular Cossprayer ShenInin uniform.\""
},
{
"sentence_id" : 1,
"tones" : [
],
"text" : "(Entame NEXT)"
}
],
"document_tone" : {
"tones" : [
{
"score" : 0.94484500000000005,
"tone_name" : "Tentative",
"tone_id" : "tentative"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"score" : 0.77552100000000002,
"tone_name" : "Joy",
"tone_id" : "joy"
}
]
},
"sentences_tone" : [
{
"sentence_id" : 0,
"tones" : [
{
"tone_id" : "joy",
"score" : 0.62795699999999999,
"tone_name" : "Joy"
}
],
"text" : "Followers: 32.4 million!"
},
{
"sentence_id" : 1,
"tones" : [
{
"tone_id" : "joy",
"tone_name" : "Joy",
"score" : 0.75022100000000003
}
],
"text" : "The Queen of the Gravier and the Queen of the Gravies of the Gravies and the Queen of the Sainting and the Mine Tree"
}
]
}, {
"document_tone" : {
"tones" : [
{
"score" : 0.83205300000000004,
"tone_id" : "joy",
"tone_name" : "Joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Joy",
"tone_id" : "joy",
"score" : 0.53014799999999995
}
]
}
}, {
"document_tone" : {
"tones" : [
]
}
}, {
"document_tone" : {
"tones" : [
]
}
}, {
"sentences_tone" : [
{
"text" : "\"The thighs are thicker.\"",
"tones" : [
],
"sentence_id" : 0
},
{
"text" : "Yuho HONDA, Cute and Sexual Dresses (Entame NEXT)",
"tones" : [
{
"tone_id" : "joy",
"score" : 0.75571100000000002,
"tone_name" : "Joy"
}
],
"sentence_id" : 1
}
],
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"score" : 0.73423000000000005,
"tone_name" : "Joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"score" : 0.67583000000000004,
"tone_name" : "Joy"
}
]
},
"sentences_tone" : [
{
"text" : "\"Detective Conan\" with voice actors and sumptues, \"Detective Conan,\" which is too much of a love for \"Detective Conan,\" and \"Sumitai Edogawa.\"",
"tones" : [
{
"tone_id" : "joy",
"tone_name" : "Joy",
"score" : 0.70681300000000002
}
],
"sentence_id" : 0
},
{
"text" : "(\"Entame NEXT\")",
"tones" : [
],
"sentence_id" : 1
}
]
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Analytical",
"tone_id" : "analytical",
"score" : 0.84622399999999998
},
{
"tone_name" : "Tentative",
"tone_id" : "tentative",
"score" : 0.61621599999999999
}
]
},
"sentences_tone" : [
{
"text" : "\"I don't feel comfortable with the Dokidoki\" (Entame NEXT), which is also known as \"Suta Akari,\" and the girl's favorite helcey.",
"tones" : [
{
"score" : 0.58152999999999999,
"tone_name" : "Joy",
"tone_id" : "joy"
}
],
"sentence_id" : 0
},
{
"text" : "\" I don't feel like a dog",
"tones" : [
{
"tone_name" : "Analytical",
"score" : 0.94455100000000003,
"tone_id" : "analytical"
}
],
"sentence_id" : 1
}
]
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Analytical",
"score" : 0.82533800000000002,
"tone_id" : "analytical"
}
]
}
}, {
"document_tone" : {
"tones" : [
]
}
}, {
"document_tone" : {
"tones" : [
]
}
}, {
"sentences_tone" : [
{
"sentence_id" : 0,
"text" : "Mo Musume.Makino Mari, a swimsuit, and a sneaker's legendable offshot: \"You really are a goddess.\"",
"tones" : [
{
"tone_name" : "Analytical",
"score" : 0.50676299999999996,
"tone_id" : "analytical"
}
]
},
{
"sentence_id" : 1,
"tones" : [
],
"text" : "(Entame NEXT)"
}
],
"document_tone" : {
"tones" : [
{
"tone_name" : "Analytical",
"tone_id" : "analytical",
"score" : 0.64375800000000005
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"score" : 0.66994399999999998,
"tone_name" : "Joy",
"tone_id" : "joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_name" : "Joy",
"score" : 0.91817700000000002,
"tone_id" : "joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"score" : 0.61852099999999999,
"tone_name" : "Joy",
"tone_id" : "joy"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"tone_name" : "Joy",
"score" : 0.50842900000000002
}
]
},
"sentences_tone" : [
{
"text" : "Queen Inster in the Graviar world, Inster-Sakuchimi, said: \"Anyway, I'm aware of this by shooting.\"",
"tones" : [
],
"sentence_id" : 0
},
{
"text" : "(\"Entame Next\")",
"tones" : [
],
"sentence_id" : 1
}
]
}, {
"document_tone" : {
"tones" : [
{
"tone_id" : "sadness",
"score" : 0.503888,
"tone_name" : "Sadness"
},
{
"tone_id" : "analytical",
"score" : 0.57936699999999997,
"tone_name" : "Analytical"
}
]
}
}, {
"document_tone" : {
"tones" : [
{
"tone_id" : "joy",
"tone_name" : "Joy",
"score" : 0.84084999999999999
}
]
}
}]
Angenommen, Sie haben solche JSON-formatierten Daten und möchten die Indexnummer eines Elements abrufen, das bestimmte Bedingungen erfüllt. Die diesmal angegebenen Bedingungen sind, dass "Tonname" Freude "und" Punktzahl "0,5 oder mehr ist".
JsonAnalysisModel.swift
class JsonAnalysisModel {
//Eigenschaften, die beim JSON-Parsing verwendet werden
var count = 0
var arrayCount = 35
var sampleJsonArray: [JSON] = []
var joyCountArray : [Any] = []
#Kürzung
//Methodenerstellung
func startJsonAnalysis() {
//Bestätigung von JSON-Daten (#Daten werden durch Überprüfen der JSON-Daten angezeigt.
print(sampleJsonArray.debugDescription)
//Iterieren Sie so oft, wie Elemente in sampleJsonArray (-Konsistenz bei 1)
for i in 0...arrayCount-1 {
//JSON-Daten"Joy" &&Punktzahl ist 0.Grenzen Sie die Bedingungen mit 5 oder mehr Elementen ein(Suchen Sie hier nach Elementen)
if sampleJsonArray[i]["document_tone"]["tones"][count]["score"] > 0.5 && sampleJsonArray[i]["document_tone"]["tones"][count]["tone_name"] == "Joy" {
//Rufen Sie die Indexnummer des Elements ab, das die Bedingungen erfüllt (-Konsistenz bei 1)
joyCountArray.append(sampleJsonArray[0].count+i-1)
}
}
//Bestätigung des Akquisitionsergebnisses
print("joyCountArray: \(joyCountArray)")
}
}
Lassen Sie uns das Protokoll überprüfen.
joyCountArray: [0, 2, 3, 4, 5, 6, 11, 12, 13, 14, 17, 18, 19, 22, 23, 29, 30, 31, 32, 34]
Jetzt haben Sie ** den JSON analysiert und den Index des Elements erhalten, das die Bedingungen erfüllt **!
Dieses Mal habe ich über ** Wie man komplexes JSON analysiert und den Index des Elements erhält, das die Bedingung erfüllt ** durch Anwenden der JSON-Analyse gepostet. Da Swift häufig JSON-Analysen durchführt, muss es in der Lage sein, verschiedene Bedingungen zu verarbeiten.
Danke, dass du bis zum Ende zugesehen hast!