String returning empty

Asked

Viewed 150 times

0

I am trying to get me into the . zip file, select a single file called mcmod.info and save for a MemoryStream temporary.

I followed as a basis that link on Stackoverflow, but when I read the var ms = new MemoryStream() using a var texto = new StreamReader(ms).ReadToEnd(); and make you use MessageBox.Show(texto); Messagebox returns an empty String.

  ZipFile zf = ZipFile.Read(@"C:\big-reactors.zip");
  ZipEntry ze = zf["mcmod.info"];

  MemoryStream memory_stream = new MemoryStream();
  ze.Extract(memory_stream);

  TextReader text_reader = new StreamReader(memory_stream);
  string json = text_reader.ReadToEnd();

   MessageBox.Show(json);

In the archive mcmod.info contains type json, those lines:

[
  {
    "modid": "BigReactors",
    "name": "Big Reactors",
    "description": "Adds large, multiblock power generation machines to Minecraft. Compatible with Redstone Flux (RF) power.",
    "version": "0.4.3A",
    "mcversion": "1.7.10",
    "url": "http://www.big-reactors.com",
    "updateUrl": "",
    "authorList": ["ErogenousBeef"],
    "credits": "powercrystals, skyboy, King_Lemming, & Calclavia for example code",
   "logoFile": "",
   "screenshots": [],
   "dependencies": [
        "MinecraftForge", "CoFHCore"
       ] 
   }
]

I’ve already made a code that does his deserialization, but the focus at the moment is that I get feedback from Stream.ReadToEnd();

I used it to deserialize:

public class MCModInfo
{
    public string modid { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public string version { get; set; }
    public string mcversion { get; set; }
    public string url { get; set; }
    public string updateUrl { get; set; }
    public List<string> authorList { get; set; }
    public string credits { get; set; }
    public string logoFile { get; set; }
    public List<string> screenshots { get; set; }
    public string parent { get; set; }
    public List<string> requiredMods { get; set; }
    public List<string> dependencies { get; set; }
    public List<string> dependants { get; set; }
    public bool useDependencyInformation { get; set; }
}

public class MCModInfo_Parser
{
    public MCModInfo Deserialize(string json)
    {
        return JsonConvert.DeserializeObject<MCModInfo>(json);
    }

    public string Serialize(MCModInfo mcmodinfo)
    {
        return JsonConvert.SerializeObject(mcmodinfo);
    }
}

1 answer

1


I found out! After the creation of Memorystream I have to make her come back from the beginning.

memory_stream.Seek(0, SeekOrigin.Begin);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.